![]()
From: Jose Kahan (Jose.Kahan@inrialpes.fr)
Date: Thu Jul 01 1999 - 11:51:33 CDT
(Sorry for the multiple posting. I'm not sure if the mailing lists
are working.)
Hello,
Yesterday I sent a patch. However, I noticed today that one of my
changes in parse.c broke some of the MIME handling. Here's a new
version of my parse.c patch, which fixes the problem.
Apply this patch against your CVS parse.c.
Cheers,
-Jose
*** parse.c Thu Jul 1 18:34:48 1999
--- /home/pommier/kahan/hypermail/src/parse.c Mon Jun 7 19:21:42 1999
***************
*** 85,125 ****
return (inlist(set_inline_types, type));
}
! int preferedcontent(int *current_weight, char *type)
{
- int weight;
- int status;
-
- status = 0;
-
/* We let plain text remain PREFERED at all times */
! if(!strcasecmp("text/plain", type)) {
! if (*current_weight != 0) {
! /* to avoid having two text/plain alternatives */
! *current_weight = 0;
! status = 1;
! }
! }
! /* find the weight of the type arg. If the weight is
! inferior to the current_weight, we make it the
! prefered content */
! else if (set_prefered_types) {
! weight = inlist_pos (set_prefered_types, type);
! if (weight != -1) {
! /* +1 so that weight 0 is reserved for text/plain */
! weight++;
! if (*current_weight == -1) {
! *current_weight = weight;
! status = 1;
! }
! else if (*current_weight > weight) {
! *current_weight = weight;
! status = 1;
! }
! }
}
! return status;
}
int textcontent(char *type)
--- 85,105 ----
return (inlist(set_inline_types, type));
}
! int preferedcontent(char *type)
{
/* We let plain text remain PREFERED at all times */
! if(!strcasecmp("text/plain", type))
! return 1;
!
! /*
! ** Parsing for embedded html needs more work before we
! ** can actually do this...
! */
! if(set_prefered_types) {
! return (inlist(set_prefered_types, type));
}
! return 0;
}
int textcontent(char *type)
***************
*** 917,939 ****
int num, isinheader, hassubject, hasdate;
struct emailinfo *emp;
- typedef enum {
- NO_FILE,
- MAKE_FILE,
- MADE_FILE
- } FileStatus; /* for attachments */
-
/* -- variables for the multipart/alternative parser -- */
struct body *origbp=NULL; /* store the original bp */
struct body *origlp=NULL; /* ... and the original lp */
char alternativeparser=FALSE; /* set when inside alternative parser mode */
- int alternative_weight=-1; /* the current weight of the prefered alternative content */
- struct body *alternative_lp; /* the previous alternative lp */
- struct body *alternative_bp; /* the previous alternative bp */
- FileStatus alternative_lastfile_created = NO_FILE; /* previous alternative attachments, for non-inline MIME types */
- char alternative_file[129]; /* file name where we store the non-inline alternatives */
- char alternative_lastfile[129]; /* last file name where we store the non-inline alternatives */
-
/* -- end of alternative parser variables -- */
struct body *bp;
--- 897,906 ----
***************
*** 967,973 ****
char *boundary;
char type[129]; /* for Content-Type type */
char charbuffer[129]; /* for Content-Type charset */
! FileStatus file_created = NO_FILE; /* for attachments */
char attachname[129]; /* for attachment file names */
--- 934,944 ----
char *boundary;
char type[129]; /* for Content-Type type */
char charbuffer[129]; /* for Content-Type charset */
! enum {
! NO_FILE,
! MAKE_FILE,
! MADE_FILE
! } file_created = NO_FILE; /* for attachments */
char attachname[129]; /* for attachment file names */
***************
*** 1043,1053 ****
** we mark this as a header-line, and we use it to
** track end-of-header displays
*/
!
! /* skip the alternate "\n", otherwise, we'll have
! an extra "\n" in the HTMLized message */
! if (!alternativeparser)
! bp = addbody(bp, &lp, line, BODY_HEADER|bodyflags);
isinheader--;
/*
--- 1014,1020 ----
** we mark this as a header-line, and we use it to
** track end-of-header displays
*/
! bp = addbody(bp, &lp, line, BODY_HEADER|bodyflags);
isinheader--;
/*
***************
*** 1168,1230 ****
charset = strsav(charbuffer);
}
! if (alternativeparser) {
! struct body *next, *temp_bp;
!
! /* We are parsing alternatives... */
! if(preferedcontent(&alternative_weight, type) ) {
! /* ... this is a prefered type, we want to store
this [instead of the earlier one]. */
#if 0
! printf("%s is more fun than the previous one\n",
! type);
#endif
! /* erase the previous alternative info */
! temp_bp = alternative_bp; /* remember the value of bp for GC */
! alternative_bp = alternative_lp = NULL;
! alternative_lastfile_created = NO_FILE;
! content = CONTENT_UNKNOWN;
! if (alternative_lastfile[0] != '\0') {
! /* remove the previous attachment */
! unlink (alternative_lastfile);
! alternative_lastfile[0] = '\0';
! }
}
else {
/* ...and this type is not a prefered one. Thus, we
* shall ignore it completely! */
content = CONTENT_IGNORE;
- /* erase the current alternative info */
- temp_bp = bp; /* remember the value of bp for GC */
- lp = alternative_lp;
- bp = alternative_bp;
- strcpy (alternative_file, alternative_lastfile);
- file_created = alternative_lastfile_created;
- alternative_bp = alternative_lp = NULL;
- alternative_lastfile_created = NO_FILE;
- alternative_lastfile[0] = '\0';
- /* we haven't yet created any attachment file, so there's no need
- to erase it yet */
}
! /* free any previous alternative */
! while (temp_bp) {
! next = temp_bp->next;
! if (temp_bp->line) free (temp_bp->line);
! free (temp_bp);
! temp_bp = next;
! }
! /* @@ not sure if I should add a diff flag to do this break */
! if (content == CONTENT_IGNORE)
! /* end the header parsing... we already know what we want */
! break;
! }
!
! if (content == CONTENT_IGNORE)
! continue;
! else if (ignorecontent(type))
! /* don't save this */
! content = CONTENT_IGNORE;
else if (textcontent(type) ||
(inlinehtml && !strcasecmp(type, "text/html"))) {
/* text content or text/html follows.
--- 1135,1178 ----
charset = strsav(charbuffer);
}
! if(alternativeparser) {
! /* We are parsing alternatives... */
! if(preferedcontent(type) ) {
! /* ... this is a prefered type, we want to store
this [instead of the earlier one]. */
#if 0
! struct body *next;
! printf("%s is more fun than the previous one\n",
! type);
! #endif
! #if 0
! /*
! ** Not sure why this free section is here.
! ** It is causing purify to barf with massive numbers of
! ** "FMR: Free memory reads". When I commented it out it
! ** cleared up the problem with no associated memory leaked
! ** or difference in output. It's history for now.
! */
! while(bp) {
! next=bp->next;
! if (bp->line) free(bp->line);
! if (bp) free(bp);
! bp=next;
! }
#endif
! headp = NULL;
}
else {
/* ...and this type is not a prefered one. Thus, we
* shall ignore it completely! */
content = CONTENT_IGNORE;
}
! }
! if(ignorecontent(type)) {
! /* don't save this */
! content = CONTENT_IGNORE;
! }
else if (textcontent(type) ||
(inlinehtml && !strcasecmp(type, "text/html"))) {
/* text content or text/html follows.
***************
*** 1420,1437 ****
origlp=lp;
alternativeparser = TRUE;
/* restart on a new list: */
lp=bp=NULL;
- /* clean the alternative status variables */
- alternative_weight = -1;
- alternative_lp = alternative_bp = NULL;
- alternative_lastfile_created = NO_FILE;
- alternative_file[0] = alternative_lastfile[0] = '\0';
}
headp = lp; /* start at this point next time */
}
else {
! bp = addbody(bp, &lp, line, BODY_HEADER|bodyflags);
}
}
else {
--- 1368,1381 ----
origlp=lp;
alternativeparser = TRUE;
+
/* restart on a new list: */
lp=bp=NULL;
}
headp = lp; /* start at this point next time */
}
else {
! bp = addbody(bp, &lp, line, BODY_HEADER|bodyflags);
}
}
else {
***************
*** 1549,1563 ****
!strncmp(line, "--", 2) &&
!strncmp(line+2, boundp->line, strlen(boundp->line))) {
/* right at this point, we have another part coming up */
#if 0
printf("hit %s\n", line);
#endif
if (!strncmp(line+2+strlen(boundp->line), "--", 2)) {
- /* @@@ don't know why we had this line here. Doesn't hurt to take
- it out, though */
- #if 0
bp = addbody(bp,&lp,"\n",BODY_HTMLIZED|bodyflags);
! #endif
isinheader = 0; /* no header, the ending boundary
can't have any describing
headers */
--- 1493,1508 ----
!strncmp(line, "--", 2) &&
!strncmp(line+2, boundp->line, strlen(boundp->line))) {
/* right at this point, we have another part coming up */
+ isinheader = 1; /* back on a kind-of-header */
+ file_created = NO_FILE; /* not created any file yet */
+
#if 0
printf("hit %s\n", line);
#endif
if (!strncmp(line+2+strlen(boundp->line), "--", 2)) {
bp = addbody(bp,&lp,"\n",BODY_HTMLIZED|bodyflags);
!
!
isinheader = 0; /* no header, the ending boundary
can't have any describing
headers */
***************
*** 1573,1594 ****
struct body *next;
/* we no longer have alternatives */
alternativeparser = FALSE;
- /* reset the alternative variables (I think we can skip
- this step without problems */
- alternative_weight = -1;
- alternative_bp = alternative_bp = NULL;
- alternative_lastfile_created = NO_FILE;
- alternative_file[0] = alternative_lastfile[0] = '\0';
#if 0
! printf("We DUMP the chosen alternative\n");
#endif
while(bp) {
! origbp = addbody(origbp, &origlp,
! bp->line,
! (bp->header?BODY_HEADER:0)|
! (bp->html?BODY_HTMLIZED:0)|
! (bp->attached?BODY_ATTACHED:0)
! );
next= bp->next;
free(bp->line);
free(bp);
--- 1518,1533 ----
struct body *next;
/* we no longer have alternatives */
alternativeparser = FALSE;
#if 0
! printf("We DUMP an old alternative\n");
#endif
while(bp) {
! origbp = addbody(origbp, &origlp,
! bp->line,
! (bp->header?BODY_HEADER:0)|
! (bp->html?BODY_HTMLIZED:0)|
! (bp->attached?BODY_ATTACHED:0)
! );
next= bp->next;
free(bp->line);
free(bp);
***************
*** 1605,1629 ****
else
printf("back to NONE\n");
#endif
! } else {
! if (alternativeparser) {
! /*
! ** parsing another alternative, so we save the
! ** precedent values
! */
! alternative_bp = bp;
! alternative_lp = lp;
! alternative_lastfile_created = file_created;
! strcpy (alternative_lastfile, alternative_file);
! /* and now reset them */
! headp = bp = lp= NULL;
! alternative_file[0] = '\0';
! }
! isinheader = 1; /* back on a kind-of-header */
! /* @@@ why the below thing??? */
! file_created = NO_FILE; /* not created any file yet */
! }
!
if (-1 != binfile) {
close(binfile);
binfile=-1;
--- 1544,1551 ----
else
printf("back to NONE\n");
#endif
! }
!
if (-1 != binfile) {
close(binfile);
binfile=-1;
***************
*** 1770,1786 ****
if(-1 != binfile) {
chmod(binname, set_filemode);
if(set_showprogress)
print_progress(num,lang[MSG_CREATED_ATTACHMENT_FILE],binname);
- if (alternativeparser)
- /* save the last name, in case we need to supress it */
- strncpy (alternative_file, binname, sizeof (alternative_file) -1);
- } else {
- if (alternativeparser)
- /* save the last name, in case we need to supress it */
- alternative_file[0] = '\0';
- }
-
file=strrchr(binname, PATH_SEPARATOR);
if (file)
file++; /* pass the separator */
--- 1692,1701 ----
if(-1 != binfile) {
chmod(binname, set_filemode);
if(set_showprogress)
+
print_progress(num,lang[MSG_CREATED_ATTACHMENT_FILE],binname);
+ }
file=strrchr(binname, PATH_SEPARATOR);
if (file)
file++; /* pass the separator */
***************
*** 1818,1826 ****
else
content = CONTENT_UNKNOWN;
! if (!nameisuniq && binname) {
free(binname);
- }
}
}
#endif
--- 1733,1740 ----
else
content = CONTENT_UNKNOWN;
! if (!nameisuniq && binname)
free(binname);
}
}
#endif
![]()