aboutsummaryrefslogtreecommitdiffstats
path: root/util/strgutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/strgutil.c')
-rw-r--r--util/strgutil.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/util/strgutil.c b/util/strgutil.c
index 402881a6e..620fb33bc 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -455,6 +455,56 @@ string_count_chr( const char *string, int c )
return count;
}
+
+/* Check whether the string has characters not valid in an RFC-822
+ address. To cope with OpenPGP we ignore non-ascii characters
+ so that for example umlauts are legal in an email address. An
+ OpenPGP user ID must be utf-8 encoded but there is no strict
+ requirement for RFC-822. Thus to avoid IDNA encoding we put the
+ address verbatim as utf-8 into the user ID under the assumption
+ that mail programs handle IDNA at a lower level and take OpenPGP
+ user IDs as utf-8. Note that we can't do an utf-8 encoding
+ checking here because in keygen.c this function is called with the
+ native encoding and native to utf-8 encoding is only done later. */
+int
+has_invalid_email_chars (const char *s)
+{
+ int at_seen=0;
+ const char *valid_chars=
+ "01234567890_-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ for ( ; *s; s++ )
+ {
+ if ( *s & 0x80 )
+ continue; /* We only care about ASCII. */
+ if ( *s == '@' )
+ at_seen=1;
+ else if ( !at_seen && !( !!strchr( valid_chars, *s ) || *s == '+' ) )
+ return 1;
+ else if ( at_seen && !strchr( valid_chars, *s ) )
+ return 1;
+ }
+ return 0;
+}
+
+
+/* Check whether NAME represents a valid mailbox according t
+ RFC822. Returns true if so. */
+int
+is_valid_mailbox (const char *name)
+{
+ return !( !name
+ || !*name
+ || has_invalid_email_chars (name)
+ || string_count_chr (name,'@') != 1
+ || *name == '@'
+ || name[strlen(name)-1] == '@'
+ || name[strlen(name)-1] == '.'
+ || strstr (name, "..") );
+}
+
+
+
#ifdef USE_GNUPG_ICONV
static void
handle_iconv_error (const char *to, const char *from, int use_fallback)