Results 1 to 3 of 3
HI all,
Is there any good MIME email message parser wrote in C?
Thanks a lot....
- 03-21-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 1
MIME Email parser in C (not c++ plz)
HI all,
Is there any good MIME email message parser wrote in C?
Thanks a lot.
- 03-21-2007 #2Just Joined!
- Join Date
- Jan 2007
- Posts
- 23
email parser
u can try gmime, msgsdk ...........
- 03-21-2007 #3Just Joined!
- Join Date
- Mar 2007
- Posts
- 2
I wrote the below about a year and it works great. Give it a whirl.
Originally Posted by datasunny
Code:#ifndef TRUE # define TRUE 1 #endif #ifndef FALSE # define FALSE 0 #endif typedef int bool; /* * Please refer to http://en.wikipedia.org/wiki/Email_address for a * description of acceptable characters in an email. The information * there is extracted from rfc2821 and is much easier to understand. * * Please refer to rfc2821: section 4.5.3.1 "Size limits and minimums" for * the defined local-part and domain size limits. * * This does not support quoted local-parts: "foo"@bar.com will be FALSE. */ bool strisemail(const char *email) { int domain_count = 0; bool have_atsign = FALSE; const char *e = email; if(!e || !*e || *e=='.') return FALSE; /* LOCAL-PART limited to 64 characters */ for(; *e; ++e) { if(e-email >= 64) return FALSE; switch(*e) { case '@': if(*(e-1) == '.') return FALSE; ++e; have_atsign = TRUE; goto LOCAL_PART_END; /* local-part acceptable characters */ case '.': case '-': case '_': case '!': case '#': case '$': case '%': case '&': case '\'': case '*': case '+': case '/': case '=': case '?': case '^': case '`': case '{': case '|': case '}': case '~': break; default: if(!isalnum(*e)) return FALSE; } } LOCAL_PART_END: if(e-email < 2 || !have_atsign || *e=='.') /* no @. */ return FALSE; /* DOMAIN: A max of 4 sub-domains limited to 255. */ for(; *e; ++e) { if(e-email >= 255) return FALSE; switch(*e) { /* found subdomain */ case '.': if(++domain_count > 4) return FALSE; /* fall-thru */ case '-': case '_': break; default: if(!isalnum(*e)) return FALSE; } } /* I think [.-_] can be in the extension, just not last char? I also make sure there is at least a 2 char extension. */ return domain_count && e-email >= 6 && e-email < (255 + 64) && *(e-1) != '.' && *(e-2) != '.'; }


Reply With Quote