I have need to match based on any subdomain (without knowing what that
subdomain may be).  Changing table_mailaddr_match to the following would
allow @*.example.com to match @sub.example.com and @sub2.example.com.

Note, in this example @example.com would not match since the period is
included in the check.  While @*example.com would catch that as well, it
would also catch @forexample.com.

Thoughts?

int
table_mailaddr_match(const char *s1, const char *s2)
{
   struct mailaddr m1;
   struct mailaddr m2;

   if (! text_to_mailaddr(&m1, s1))
      return 0;
   if (! text_to_mailaddr(&m2, s2))
      return 0;

   if (m2.domain[0] && m2.domain[0] == '*') {
      size_t m1_len = strlen(m1.domain);
      size_t m2_len = strlen(m2.domain);

      if (m1_len < m2_len - 1)
         return 0;
      if (strcasecmp(&m1.domain[m1_len - m2_len + 1], &m2.domain[1]))
         return 0;
   } else if (strcasecmp(m1.domain, m2.domain))
      return 0;

   if (m2.user[0])
      if (strcasecmp(m1.user, m2.user))
         return 0;
   return 1;
}

Reply via email to