summaryrefslogtreecommitdiff
path: root/ext/mailparse/rfc2045acchk.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2001-05-20 11:11:28 +0000
committerWez Furlong <wez@php.net>2001-05-20 11:11:28 +0000
commit6468f8b492040c8e973608fa41c5c64a6e2434b2 (patch)
tree2d1737225dd746b4c20c0474598fca3f55c25c95 /ext/mailparse/rfc2045acchk.c
parent83b18832aa9f252a8f9f47536867a982d143e030 (diff)
downloadphp-git-6468f8b492040c8e973608fa41c5c64a6e2434b2.tar.gz
Imported mailparse extension
@- New mailparse extension for parsing and manipulating MIME mail (Wez)
Diffstat (limited to 'ext/mailparse/rfc2045acchk.c')
-rw-r--r--ext/mailparse/rfc2045acchk.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/ext/mailparse/rfc2045acchk.c b/ext/mailparse/rfc2045acchk.c
new file mode 100644
index 0000000000..8fcd16dbaf
--- /dev/null
+++ b/ext/mailparse/rfc2045acchk.c
@@ -0,0 +1,123 @@
+/* $Id$ */
+/*
+** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
+** distribution information.
+*/
+#include "php.h"
+#include "php_mailparse.h"
+
+
+int rfc2045_ac_check(struct rfc2045 *p, int rwmode)
+{
+ int flag=0; /* Flag - rewriting suggested */
+ struct rfc2045 *c;
+ int hasnon7bit=p->has8bitchars;
+ /* hasnon7bit: 8bit chars in this section or subsections */
+ const char *te;
+ int is8bitte;
+ MAILPARSELS_FETCH();
+
+ for (c=p->firstpart; c; c=c->next)
+ if (!c->isdummy)
+ {
+ if (rfc2045_ac_check(c, rwmode)) flag=1;
+ if (strcmp(c->content_transfer_encoding, "7bit") &&
+ strcmp(c->content_transfer_encoding, "quoted-printable"))
+ hasnon7bit=1;
+ if (c->has8bitchars)
+ p->has8bitchars=1;
+ }
+
+ if (RFC2045_ISMIME1DEF(p->mime_version) && !p->content_type)
+ {
+ p->content_type = estrdup("text/plain");
+ if (p->mime_version)
+ {
+ flag=1;
+ }
+ }
+
+ if (RFC2045_ISMIME1DEF(p->mime_version)
+ && !rfc2045_getattr(p->content_type_attr, "charset")
+ && strncasecmp(p->content_type, "text/", 5) == 0)
+ {
+ rfc2045_setattr(&p->content_type_attr, "charset",
+ MAILPARSEG(def_charset));
+
+ if (p->mime_version
+
+ && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */
+
+ )
+ {
+ flag=1;
+ }
+ }
+
+ if (RFC2045_ISMIME1DEF(p->mime_version)
+ && !p->content_transfer_encoding)
+ {
+ p->content_transfer_encoding = estrdup(hasnon7bit ? "8bit":"7bit");
+ if (p->mime_version
+
+ && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */
+ )
+ {
+ flag=1;
+ }
+ }
+
+#if 0
+ if (RFC2045_ISMIME1DEF(p->mime_version)
+ && strncmp(p->content_type, "text/", 5) == 0 && !hasnon7bit
+ && strcmp(p->content_transfer_encoding, "7bit"))
+ {
+ if (p->mime_version)
+ {
+ flag=1;
+ }
+ }
+#endif
+
+ if (RFC2045_ISMIME1DEF(p->mime_version))
+ {
+ /* Check for conversions */
+
+ te=p->content_transfer_encoding;
+ is8bitte=strcasecmp(te, "base64") &&
+ strcasecmp(te, "quoted-printable") &&
+ strcasecmp(te, "7bit"); /* 8 bit contents */
+
+ if (is8bitte && !p->has8bitchars && !p->haslongline)
+ {
+ if (p->rw_transfer_encoding)
+ efree(p->rw_transfer_encoding);
+ p->rw_transfer_encoding=estrdup("7bit");
+ flag=1;
+ is8bitte=0;
+ }
+
+ if (rwmode == RFC2045_RW_7BIT && (is8bitte || p->haslongline))
+ {
+ if (p->rw_transfer_encoding)
+ efree(p->rw_transfer_encoding);
+ p->rw_transfer_encoding=estrdup("quoted-printable");
+ flag=1;
+ }
+ else if (rwmode == RFC2045_RW_8BIT &&
+ strcasecmp(te, "quoted-printable") == 0 &&
+ !p->haslongline)
+ {
+ if (p->rw_transfer_encoding)
+ efree(p->rw_transfer_encoding);
+ p->rw_transfer_encoding=estrdup(hasnon7bit ? "8bit":"7bit");
+ flag=1;
+ }
+ }
+
+ if (!p->mime_version)
+ {
+ p->mime_version = estrdup("1.0");
+ }
+ return (flag);
+}