openbsd-ports/mail/metamail/patches/patch-metamail_mailto_c
pvalchev 948da84411 fgets pertains the newline, while gets does not.
fix this so it accepts input... whoever did the conversion did not test
from PR 3603 by Geoff Steckel <gwes@oat.com>
2004-05-06 22:45:08 +00:00

174 lines
8.1 KiB
Plaintext

$OpenBSD: patch-metamail_mailto_c,v 1.2 2004/05/06 22:45:08 pvalchev Exp $
--- metamail/mailto.c.orig 1994-02-09 13:30:26.000000000 -0700
+++ metamail/mailto.c 2004-05-06 16:40:04.000000000 -0600
@@ -195,7 +195,7 @@ tmpname() {
sprintf(s, "%s/mm.XXXXXX", tmproot);
}
#endif
- mktemp(s);
+/* mktemp(s);*/
return(s);
}
@@ -205,7 +205,7 @@ TildeHelp() {
FILE *fp;
strcpy(TmpName, tmpname());
- fp = fopen(TmpName, "w");
+ fp = fdopen(mkstemp(TmpName), "w");
if (!fp) fp = stdout;
fprintf(fp, "The following tilde escapes are BSD-mail-compatible:\n");
fprintf(fp, "~? Show help on tilde escapes\n");
@@ -570,6 +570,7 @@ char **argv;
if (isupper(*sdum)) *sdum = tolower(*sdum);
}
if (strcmp(CharacterSet, "us-ascii")
+ && strcmp(CharacterSet, "koi8-r")
&& strncmp(CharacterSet, "iso-8859-", 9)) {
fprintf(stderr, "mailto: Unsupported character set: %s\n", CharacterSet);
exit(-1);
@@ -591,7 +592,7 @@ char **argv;
}
FirstPart = NewPart();
CurrentPart = FirstPart;
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Can't open temporary file %s\n", CurrentPart->filename);
cleanexit(-1);
@@ -678,7 +679,7 @@ char **argv;
CurrentPart->next = NewPart();
CurrentPart->next->prev = CurrentPart;
CurrentPart = CurrentPart->next;
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Can't open temporary file %s\n", CurrentPart->filename);
cleanexit(-1);
@@ -717,7 +718,7 @@ char **argv;
CurrentPart = CurrentPart->next;
CurrentPart->istext = 0;
CurrentPart->content_type = "message/rfc822";
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Cannot open temporary file %s\n", CurrentPart->filename);
break;
@@ -729,7 +730,7 @@ char **argv;
CurrentPart->next = NewPart();
CurrentPart->next->prev = CurrentPart;
CurrentPart = CurrentPart->next;
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Can't open temporary file %s\n", CurrentPart->filename);
cleanexit(-1);
@@ -808,11 +809,11 @@ char **argv;
char Cmd[TMPFILE_NAME_SIZE + 15];
char *s=tmpname();
fclose(fpout);
- fptmp = fopen(s, "w");
+ fptmp = fdopen(mkstemp(s), "w");
WriteOutMessage(fptmp, ToList, Subject, CCList, FirstPart);
TempCloseStyles(fptmp);
fclose(fptmp);
- fpout = fopen(CurrentPart->filename, "a");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "a");
if (!fpout) {
fprintf(stderr, "mailto: Can't open temporary file %s\n", CurrentPart->filename);
cleanexit(-1);
@@ -969,7 +970,7 @@ char **argv;
CurrentPart = CurrentPart->next;
CurrentPart->istext = 0;
CurrentPart->content_type = "message/rfc822";
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Cannot open temporary file %s\n", CurrentPart->filename);
break;
@@ -991,7 +992,7 @@ char **argv;
CurrentPart->next = NewPart();
CurrentPart->next->prev = CurrentPart;
CurrentPart = CurrentPart->next;
- fpout = fopen(CurrentPart->filename, "w");
+ fpout = fdopen(mkstemp(CurrentPart->filename), "w");
if (!fpout) {
fprintf(stderr, "mailto: Can't open temporary file %s\n", CurrentPart->filename);
cleanexit(-1);
@@ -1130,6 +1131,7 @@ struct mailpart *part;
if (part->isrich) {
if (strcmp(CharacterSet, "us-ascii")
&& (strncmp(CharacterSet, "iso-8859-", 9)
+ && strcmp(CharacterSet, "koi8-r")
|| part->encoding_type_needed != ENC_NONE)) {
fprintf(fp, "Content-type: text/richtext; charset=\"%s\"\n", CharacterSet);
} else {
@@ -1140,6 +1142,7 @@ struct mailpart *part;
WriteCtypeNicely(fp, part->content_type);
if (strcmp(CharacterSet, "us-ascii")
&& (strncmp(CharacterSet, "iso-8859-", 9)
+ && strcmp(CharacterSet, "koi8-r")
|| part->encoding_type_needed != ENC_NONE)) {
fprintf(fp, "; charset=\"%s\"\n", CharacterSet);
} else fputs("\n", fp);
@@ -1745,6 +1748,7 @@ CreateNewPart() {
}
printf("\n\nEnter your choice as a number from 0 to %d: ", i);
fflush(stdout);
+ *LineBuf = '\0';
fgets(LineBuf, sizeof(LineBuf), stdin);
ans = atoi(LineBuf);
if (ans == 0 || ans == 1) {
@@ -1773,7 +1777,7 @@ CreateNewPart() {
printf("Cannot read %s, data insertion cancelled\n", sdum);
return(NULL);
}
- fpo = fopen(mp->filename, "w");
+ fpo = fdopen(mkstemp(mp->filename), "w");
if (!fpo) {
printf("Cannot open temporary file, data insertion cancelled\n");
return(NULL);
@@ -1791,12 +1795,13 @@ CreateNewPart() {
int ct;
printf("\nEnter the MIME Content-type value for the data from file %s\n (type '?' for a list of locally-valid content-types): ", sdum);
fflush(stdout);
- gets(LineBuf);
+ fgets(LineBuf, sizeof(LineBuf), stdin);
if (index(LineBuf, '/')) {
char lc[100], *s, AnsBuf[100];
strcpy(lc, LineBuf);
for (s=lc; *s; ++s) {
if (isupper(*s)) *s = tolower(*s);
+ if (*s == '\n') *s = '\0';
}
if (!strcmp(lc, "text/plain")) break;
if (!strcmp(lc, "application/octet-stream")) break;
@@ -1809,7 +1814,7 @@ CreateNewPart() {
}
if (mc) break;
printf("The MIME content-type '%s' is not listed in your local mailcap files,\nand may not be a valid MIME type. Do you want to use it anyway [no] ? ", LineBuf);
- s = gets(AnsBuf);
+ s = fgets(AnsBuf, sizeof(AnsBuf), stdin);
while (s && *s && isspace((unsigned char) *s)) ++s;
if (s && (*s == 'y' || *s == 'Y')) break;
continue;
@@ -1866,7 +1871,8 @@ CreateNewPart() {
mp->content_type = mc->contenttype;
mp->encoding_type_needed = WhichEncodingForFile(mp->filename, mp->content_type);
} else {
- char c, LineBuf[1000], *colon, *ctypebuf = NULL, *cencbuf = NULL, *s, *newfilename;
+ char LineBuf[1000], *colon, *ctypebuf = NULL, *cencbuf = NULL, *s, *newfilename;
+ int c;
FILE *fp, *fpout;
int inheaders=1, bct=0;
@@ -1936,7 +1942,7 @@ CreateNewPart() {
mp->encoding_type_needed = ENC_NONE;
}
newfilename = tmpname();
- fpout = fopen(newfilename, "w");
+ fpout = fdopen(mkstemp(newfilename), "w");
if (!fpout) {
fprintf(stderr, "Cannot open file %s for writing, no data included.\n", newfilename);
free(CmdBuf);