Back to index

courier  0.68.2
rfc2045acchk.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2001 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 #if    HAVE_CONFIG_H
00007 #include "rfc2045_config.h"
00008 #endif
00009 #include      "rfc2045.h"
00010 #include      <string.h>
00011 #if    HAVE_STRINGS_H
00012 #include      <strings.h>
00013 #endif
00014 #include      <stdlib.h>
00015 #include      <stdio.h>
00016 
00017 
00018 extern void rfc2045_enomem();
00019 
00020 int rfc2045_ac_check(struct rfc2045 *p, int rwmode)
00021 {
00022 int    flag=0;              /* Flag - rewriting suggested */
00023 struct rfc2045 *c;
00024 int    hasnon7bit=p->has8bitchars;
00025               /* hasnon7bit: 8bit chars in this section or subsections */
00026 const char *te;
00027 int    is8bitte;
00028 
00029        for (c=p->firstpart; c; c=c->next)
00030               if (!c->isdummy)
00031               {
00032                      if (rfc2045_ac_check(c, rwmode))   flag=1;
00033                      if (c->content_transfer_encoding &&
00034                          strcmp(c->content_transfer_encoding, "7bit") &&
00035                          strcmp(c->content_transfer_encoding, "uuencode") &&
00036                             strcmp(c->content_transfer_encoding, "quoted-printable"))
00037                             hasnon7bit=1;
00038                      if (c->has8bitchars)
00039                             p->has8bitchars=1;
00040               }
00041 
00042        if (RFC2045_ISMIME1DEF(p->mime_version) && !p->content_type)
00043        {
00044               if ((p->content_type=strdup("text/plain")) == 0)
00045                      rfc2045_enomem();
00046               if (p->mime_version)
00047               {
00048                      flag=1;
00049               }
00050        }
00051 
00052        if (RFC2045_ISMIME1DEF(p->mime_version)
00053               && !rfc2045_getattr(p->content_type_attr, "charset")
00054               && strncasecmp(p->content_type, "text/", 5) == 0)
00055        {
00056               if (rfc2045_attrset(&p->content_type_attr, "charset",
00057                                 rfc2045_getdefaultcharset()) < 0)
00058                      rfc2045_enomem();
00059 
00060               if (p->mime_version
00061 
00062                      && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */
00063 
00064                      )
00065               {
00066                      flag=1;
00067               }
00068        }
00069 
00070        if (RFC2045_ISMIME1DEF(p->mime_version)
00071               && !p->content_transfer_encoding)
00072        {
00073               if ((p->content_transfer_encoding=strdup(
00074                      hasnon7bit ? "8bit":"7bit")) == 0)
00075                      rfc2045_enomem();
00076               if (p->mime_version
00077 
00078                      && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */
00079                      )
00080               {
00081                      flag=1;
00082               }
00083        }
00084 
00085 #if 0
00086        if (RFC2045_ISMIME1DEF(p->mime_version)
00087               && strncmp(p->content_type, "text/", 5) == 0 && !hasnon7bit
00088               && strcmp(p->content_transfer_encoding, "7bit"))
00089        {
00090               if (p->mime_version)
00091               {
00092                      flag=1;
00093               }
00094        }
00095 #endif
00096 
00097        if (RFC2045_ISMIME1DEF(p->mime_version))
00098        {
00099               /* Check for conversions */
00100 
00101               te=p->content_transfer_encoding;
00102               is8bitte=strcasecmp(te, "base64") &&
00103                      strcasecmp(te, "quoted-printable") &&
00104                      strcasecmp(te, "uuencode") &&
00105                      strcasecmp(te, "7bit");     /* 8 bit contents */
00106 
00107               if (is8bitte && !p->has8bitchars && !p->haslongline)
00108               {
00109                      if (p->rw_transfer_encoding)
00110                             free(p->rw_transfer_encoding);
00111                      if ((p->rw_transfer_encoding=strdup("7bit")) == 0)
00112                             rfc2045_enomem();
00113                      flag=1;
00114                      is8bitte=0;
00115               }
00116 
00117               if (rwmode == RFC2045_RW_7BIT && (is8bitte || p->haslongline))
00118               {
00119                      if (p->rw_transfer_encoding)
00120                             free(p->rw_transfer_encoding);
00121                      if ((p->rw_transfer_encoding=strdup("quoted-printable"))
00122                             == 0)
00123                             rfc2045_enomem();
00124                      flag=1;
00125               }
00126               else if (rwmode == RFC2045_RW_8BIT &&
00127                      strcasecmp(te, "quoted-printable") == 0 &&
00128                      !p->haslongline)
00129               {
00130                      if (p->rw_transfer_encoding)
00131                             free(p->rw_transfer_encoding);
00132                      if ((p->rw_transfer_encoding=strdup(hasnon7bit
00133                                    ? "8bit":"7bit")) == 0)
00134                             rfc2045_enomem();
00135                      flag=1;
00136               }
00137        }
00138 
00139        if (!p->mime_version)
00140        {
00141               if ((p->mime_version=strdup("1.0")) == 0)
00142                      rfc2045_enomem();
00143        }
00144        return (flag);
00145 }