aboutsummaryrefslogtreecommitdiffstats
path: root/common/mbox-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/mbox-util.c')
-rw-r--r--common/mbox-util.c71
1 files changed, 67 insertions, 4 deletions
diff --git a/common/mbox-util.c b/common/mbox-util.c
index c1f05b834..a9086a3f5 100644
--- a/common/mbox-util.c
+++ b/common/mbox-util.c
@@ -173,11 +173,12 @@ is_valid_mailbox (const char *name)
/* Return the mailbox (local-part@domain) form a standard user id.
- All plain ASCII characters in the result are converted to
- lowercase. Caller must free the result. Returns NULL if no valid
- mailbox was found (or we are out of memory). */
+ * All plain ASCII characters in the result are converted to
+ * lowercase. If SUBADDRESS is 1, '+' denoted sub-addresses are not
+ * included in the result. Caller must free the result. Returns NULL
+ * if no valid mailbox was found (or we are out of memory). */
char *
-mailbox_from_userid (const char *userid)
+mailbox_from_userid (const char *userid, int subaddress)
{
const char *s, *s_end;
size_t len;
@@ -226,6 +227,29 @@ mailbox_from_userid (const char *userid)
else
errno = EINVAL;
+ if (result && subaddress == 1)
+ {
+ char *atsign, *plus;
+
+ if ((atsign = strchr (result, '@')))
+ {
+ /* We consider a subaddress only if there is a single '+'
+ * in the local part and the '+' is not the first or last
+ * character. */
+ *atsign = 0;
+ if ((plus = strchr (result, '+'))
+ && !strchr (plus+1, '+')
+ && result != plus
+ && plus[1] )
+ {
+ *atsign = '@';
+ memmove (plus, atsign, strlen (atsign)+1);
+ }
+ else
+ *atsign = '@';
+ }
+ }
+
return result? ascii_strlwr (result): NULL;
}
@@ -241,3 +265,42 @@ is_valid_user_id (const char *uid)
return 1;
}
+
+
+/* Returns true if STRING is a valid domain name according to the LDH
+ * rule. */
+int
+is_valid_domain_name (const char *string)
+{
+ static char const ldh_chars[] =
+ "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
+ const char *s;
+
+ /* Note that we do not check the length limit of a label or the
+ * entire name */
+
+ for (s=string; *s; s++)
+ if (*s == '.')
+ {
+ if (string == s)
+ return 0; /* Dot at the start of the string. */
+ /* (may also be at the end like in ".") */
+ if (s[1] == '.')
+ return 0; /* No - double dot. */
+ }
+ else if (!strchr (ldh_chars, *s))
+ return 0;
+ else if (*s == '-')
+ {
+ if (string == s)
+ return 0; /* Leading hyphen. */
+ if (s[-1] == '.')
+ return 0; /* Hyphen at begin of a label. */
+ if (s[1] == '.')
+ return 0; /* Hyphen at start of a label. */
+ if (!s[1])
+ return 0; /* Trailing hyphen. */
+ }
+
+ return !!*string;
+}