"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libs/rfc2045/reformime.c" between
sqwebmail-5.9.3.tar.bz2 and sqwebmail-6.0.0.tar.bz2

About: SqWebMail is a CGI Webmail client for Maildir mailboxes (module of the Courier mail server).

reformime.c  (sqwebmail-5.9.3.tar.bz2):reformime.c  (sqwebmail-6.0.0.tar.bz2)
/* /*
** Copyright 1998 - 2011 Double Precision, Inc. See COPYING for ** Copyright 1998 - 2018 Double Precision, Inc. See COPYING for
** distribution information. ** distribution information.
*/ */
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "rfc2045_config.h" #include "rfc2045_config.h"
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
skipping to change at line 98 skipping to change at line 98
fprintf(stderr, "Usage: reformime [options]\n"); fprintf(stderr, "Usage: reformime [options]\n");
fprintf(stderr, " -d - parse a delivery status notification.\n"); fprintf(stderr, " -d - parse a delivery status notification.\n");
fprintf(stderr, " -e - extract contents of MIME section.\n"); fprintf(stderr, " -e - extract contents of MIME section.\n");
fprintf(stderr, " -x - extract MIME section to a file.\n"); fprintf(stderr, " -x - extract MIME section to a file.\n");
fprintf(stderr, " -X - pipe MIME section to a program.\n"); fprintf(stderr, " -X - pipe MIME section to a program.\n");
fprintf(stderr, " -i - show MIME info.\n"); fprintf(stderr, " -i - show MIME info.\n");
fprintf(stderr, " -s n.n.n.n[,n.n.n.n]* - specify MIME section(s).\n") ; fprintf(stderr, " -s n.n.n.n[,n.n.n.n]* - specify MIME section(s).\n") ;
fprintf(stderr, " -r - rewrite message, filling in missing MIME header s.\n"); fprintf(stderr, " -r - rewrite message, filling in missing MIME header s.\n");
fprintf(stderr, " -r7 - also convert 8bit/raw encoding to quoted-print able, if possible.\n"); fprintf(stderr, " -r7 - also convert 8bit/raw encoding to quoted-print able, if possible.\n");
fprintf(stderr, " -r8 - also convert quoted-printable encoding to 8bit , if possible.\n"); fprintf(stderr, " -r8 - also convert quoted-printable encoding to 8bit , if possible.\n");
fprintf(stderr, " -rU - convert quoted-printable encoding to 8bit, unc onditionally.\n");
fprintf(stderr, " -c charset - default charset for rewriting, -o, and -O.\n"); fprintf(stderr, " -c charset - default charset for rewriting, -o, and -O.\n");
fprintf(stderr, " -m [file] [file]... - create a MIME message digest.\ n"); fprintf(stderr, " -m [file] [file]... - create a MIME message digest.\ n");
fprintf(stderr, " -h \"header\" - decode RFC 2047-encoded header.\n"); fprintf(stderr, " -h \"header\" - decode RFC 2047-encoded header.\n");
fprintf(stderr, " -o \"header\" - encode unstructured header using RFC 2047.\n"); fprintf(stderr, " -o \"header\" - encode unstructured header using RFC 2047.\n");
fprintf(stderr, " -O \"header\" - encode address list header using RFC 2047.\n"); fprintf(stderr, " -O \"header\" - encode address list header using RFC 2047.\n");
exit(1); exit(1);
} }
static char *tempname(const char *tempdir) static char *tempname(const char *tempdir)
skipping to change at line 653 skipping to change at line 654
} }
static void extract_section(struct rfc2045 *top_rfcp, const char *mimesection, static void extract_section(struct rfc2045 *top_rfcp, const char *mimesection,
const char *extract_filename, int argc, char **argv, const char *extract_filename, int argc, char **argv,
void (*extract_func)(struct rfc2045 *, const char *, void (*extract_func)(struct rfc2045 *, const char *,
int, char **)) int, char **))
{ {
if (mimesection) if (mimesection)
{ {
top_rfcp=rfc2045_find(top_rfcp, mimesection); top_rfcp=rfc2045_find(top_rfcp, mimesection);
if (!mimesection) if (!top_rfcp)
notfound(mimesection); notfound(mimesection);
if (top_rfcp->firstpart) if (top_rfcp->firstpart)
{ {
fprintf(stderr, "reformime: MIME section %s is a compound section.\n", mimesection); fprintf(stderr, "reformime: MIME section %s is a compound section.\n", mimesection);
exit(1); exit(1);
} }
(*extract_func)(top_rfcp, extract_filename, argc, argv); (*extract_func)(top_rfcp, extract_filename, argc, argv);
return; return;
} }
skipping to change at line 696 skipping to change at line 697
if (addr) free(addr); if (addr) free(addr);
return; return;
} }
for (p=action; *p; ++p) for (p=action; *p; ++p)
*p=tolower((int)(unsigned char)*p); *p=tolower((int)(unsigned char)*p);
for (p=addr; *p && isspace((int)(unsigned char)*p); ++p) for (p=addr; *p && isspace((int)(unsigned char)*p); ++p)
; ;
if (strncasecmp(p, "rfc822;", 7)) if (strncasecmp(p, "rfc822;", 7) &&
strncasecmp(p, "utf-8;", 6))
{ {
free(action); free(action);
free(addr); free(addr);
return; return;
} }
for (q=action; *q && isspace((int)(unsigned char)*q); ++q) for (q=action; *q && isspace((int)(unsigned char)*q); ++q)
; ;
p += 7;
p=strchr(p, ';')+1;
while (*p && isspace((int)(unsigned char)*p)) while (*p && isspace((int)(unsigned char)*p))
++p; ++p;
printf("%s %s\n", q, p); printf("%s %s\n", q, p);
free(action); free(action);
free(addr); free(addr);
} }
static void dsn(struct rfc2045 *p, int do_orig) static void dsn(struct rfc2045 *p, int do_orig)
{ {
const char *content_type_s; const char *content_type_s;
skipping to change at line 739 skipping to change at line 742
if (strcasecmp(content_type_s, "multipart/report") || if (strcasecmp(content_type_s, "multipart/report") ||
(q=rfc2045_getattr(p->content_type_attr, "report-type")) == 0 || (q=rfc2045_getattr(p->content_type_attr, "report-type")) == 0 ||
strcasecmp(q, "delivery-status") || strcasecmp(q, "delivery-status") ||
!p->firstpart || !p->firstpart->next || !p->firstpart || !p->firstpart->next ||
!p->firstpart->next->next) !p->firstpart->next->next)
_exit(1); _exit(1);
p=p->firstpart->next->next; p=p->firstpart->next->next;
rfc2045_mimeinfo(p, &content_type_s, &content_transfer_encoding_s, rfc2045_mimeinfo(p, &content_type_s, &content_transfer_encoding_s,
&charset_s); &charset_s);
rfc2045_mimepos(p, &start_pos, &end_pos, &start_body, &dummy, &dummy); rfc2045_mimepos(p, &start_pos, &end_pos, &start_body, &dummy, &dummy);
if (strcasecmp(content_type_s, "message/delivery-status") || if (!rfc2045_delivery_status_content_type(content_type_s) ||
fseek(stdin, start_body, SEEK_SET) == -1) fseek(stdin, start_body, SEEK_SET) == -1)
_exit(1); _exit(1);
i=0; i=0;
recip=0; recip=0;
orecip=0; orecip=0;
action=0; action=0;
while (start_body < end_pos) while (start_body < end_pos)
{ {
if ((ch=getchar()) == EOF) break; if ((ch=getchar()) == EOF) break;
skipping to change at line 857 skipping to change at line 860
if ( (l=malloc(sizeof (char *) * pcnt)) == 0) if ( (l=malloc(sizeof (char *) * pcnt)) == 0)
{ {
perror("malloc"); perror("malloc");
} }
pcnt=0; pcnt=0;
for (last=first; last; last=last->next) for (last=first; last; last=last->next)
l[pcnt++]=last->fn; l[pcnt++]=last->fn;
mimedigest1(pcnt, l); mimedigest1(pcnt, l);
free(l);
while(first)
{
last=first->next;
free(first->fn);
free(first);
first=last;
}
} }
static void mimedigest1(int argc, char **argv) static void mimedigest1(int argc, char **argv)
{ {
time_t t; time_t t;
char boundarybuf[200]; char boundarybuf[200];
unsigned boundarycnt=0; unsigned boundarycnt=0;
int i; int i;
FILE *fp; FILE *fp;
int *utf8;
if (argc == 0)
return;
time (&t); time (&t);
utf8=malloc(sizeof(int)*argc);
/* Search for a suitable boundary */ /* Search for a suitable boundary */
do do
{ {
int l; int l;
sprintf(boundarybuf, "reformime_%lu_%u", sprintf(boundarybuf, "reformime_%lu_%lu_%u",
(unsigned long)t, ++boundarycnt); (unsigned long)t,
(unsigned long)getpid(),
++boundarycnt);
l=strlen(boundarybuf); l=strlen(boundarybuf);
for (i=0; i<argc; i++) for (i=0; i<argc; i++)
{ {
int err=0; int err=0;
struct rfc2045 *parser=rfc2045_alloc();
if (!parser)
{
perror(argv[i]);
exit(1);
}
if ((fp=fopen(argv[i], "r")) == 0) if ((fp=fopen(argv[i], "r")) == 0)
{ {
perror(argv[i]); perror(argv[i]);
exit(1); exit(1);
} }
while (fgets(mimebuf, sizeof(mimebuf), fp)) while (fgets(mimebuf, sizeof(mimebuf), fp))
{ {
rfc2045_parse(parser, mimebuf, strlen(mimebuf));
if (mimebuf[0] != '-' || mimebuf[1] != '-') if (mimebuf[0] != '-' || mimebuf[1] != '-')
continue; continue;
if (strncasecmp(mimebuf+2, boundarybuf, l) == 0) if (strncasecmp(mimebuf+2, boundarybuf, l) == 0)
{ {
err=1; err=1;
break; break;
} }
} }
fclose(fp); fclose(fp);
utf8[i]=parser->rfcviolation & RFC2045_ERR8BITHEADER
? 1:0;
rfc2045_free(parser);
if (err) break; if (err) break;
} }
} while (i < argc); } while (i < argc);
printf("Mime-Version:1.0\n" printf("Mime-Version:1.0\n"
"Content-Type: multipart/digest; boundary=\"%s\"\n\n%s", "Content-Type: multipart/digest; boundary=\"%s\"\n\n%s",
boundarybuf, RFC2045MIMEMSG); boundarybuf, RFC2045MIMEMSG);
for (i=0; i<argc; i++) for (i=0; i<argc; i++)
{ {
if ((fp=fopen(argv[i], "r")) == 0) if ((fp=fopen(argv[i], "r")) == 0)
{ {
perror(argv[i]); perror(argv[i]);
exit(1); exit(1);
} }
printf("\n--%s\nContent-Type: message/rfc822\n\n", printf("\n--%s\nContent-Type: %s\n\n",
boundarybuf); boundarybuf,
utf8[i] ? RFC2045_MIME_MESSAGE_GLOBAL:
RFC2045_MIME_MESSAGE_RFC822);
while (fgets(mimebuf, sizeof(mimebuf), fp)) while (fgets(mimebuf, sizeof(mimebuf), fp))
printf("%s", mimebuf); printf("%s", mimebuf);
fclose(fp); fclose(fp);
} }
free(utf8);
printf("\n--%s--\n", boundarybuf); printf("\n--%s--\n", boundarybuf);
} }
static void display_decoded_header(const char *ptr, size_t cnt, void *dummy) static void display_decoded_header(const char *ptr, size_t cnt, void *dummy)
{ {
if (cnt == 0) if (cnt == 0)
putchar('\n'); putchar('\n');
else else
fwrite(ptr, cnt, 1, stdout); fwrite(ptr, cnt, 1, stdout);
} }
skipping to change at line 1012 skipping to change at line 1043
break; break;
case 'e': case 'e':
dodecode=1; dodecode=1;
break; break;
case 'r': case 'r':
dorewrite=1; dorewrite=1;
if (optarg && *optarg == '7') if (optarg && *optarg == '7')
rwmode=RFC2045_RW_7BIT; rwmode=RFC2045_RW_7BIT;
if (optarg && *optarg == '8') if (optarg && *optarg == '8')
rwmode=RFC2045_RW_8BIT; rwmode=RFC2045_RW_8BIT;
if (optarg && *optarg == 'U')
rwmode=RFC2045_RW_8BIT_ALWAYS;
break; break;
case 'm': case 'm':
domimedigest=1; domimedigest=1;
break; break;
case 'd': case 'd':
dodsn=1; dodsn=1;
break; break;
case 'D': case 'D':
dodsn=2; dodsn=2;
break; break;
skipping to change at line 1165 skipping to change at line 1198
if (do_extract) if (do_extract)
extract_section(p, mimesection, extract_section(p, mimesection,
extract_filename, argc-argn, extract_filename, argc-argn,
argv+argn, do_extract); argv+argn, do_extract);
if (mimesection) if (mimesection)
mimesection = strtok(NULL,","); mimesection = strtok(NULL,",");
} while (mimesection != NULL); } while (mimesection != NULL);
} }
else if (dodecode) else if (dodecode)
{ {
mimesection = strtok(section,","); mimesection = section ? strtok(section,","):NULL;
do { do {
print_decode(p, mimesection); print_decode(p, mimesection);
mimesection = strtok(NULL,","); if (mimesection)
mimesection = strtok(NULL,",");
} while (mimesection != NULL); } while (mimesection != NULL);
} }
else if (dorewrite) else if (dorewrite)
rewrite(p, rwmode); rewrite(p, rwmode);
else if (dodsn) else if (dodsn)
dsn(p, dodsn == 2); dsn(p, dodsn == 2);
else if (do_extract) else if (do_extract)
{ {
mimesection = strtok(section,","); mimesection = section ? strtok(section, ","):NULL;
do { do {
extract_section(p, mimesection, extract_filename, extract_section(p, mimesection, extract_filename,
argc-argn, argv+argn, do_extract); argc-argn, argv+argn, do_extract);
mimesection = strtok(NULL,","); if (mimesection)
mimesection = strtok(NULL,",");
} while (mimesection != NULL); } while (mimesection != NULL);
} }
else if (dovalidate) else if (dovalidate)
{ {
rc=1; rc=1;
if (p->rfcviolation & RFC2045_ERR2COMPLEX) if (p->rfcviolation & RFC2045_ERR2COMPLEX)
printf("ERROR: MIME complexity.\n"); printf("ERROR: MIME complexity.\n");
else if (p->rfcviolation & RFC2045_ERRBADBOUNDARY) else if (p->rfcviolation & RFC2045_ERRBADBOUNDARY)
printf("ERROR: Ambiguous MIME boundary delimiters.\n"); printf("ERROR: Ambiguous MIME boundary delimiters.\n");
 End of changes. 21 change blocks. 
20 lines changed or deleted 55 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)