projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
check for crlf in m_getfld2
[mmh]
/
uip
/
mhbuild.c
diff --git
a/uip/mhbuild.c
b/uip/mhbuild.c
index
d636cf7
..
a233c68
100644
(file)
--- a/
uip/mhbuild.c
+++ b/
uip/mhbuild.c
@@
-45,6
+45,7
@@
static struct swit switches[] = {
{ NULL, 0 }
};
{ NULL, 0 }
};
+char *version=VERSION;
/*
** Directory to place tmp files. This must
/*
** Directory to place tmp files. This must
@@
-204,7
+205,7
@@
main(int argc, char **argv)
if ((cp = context_find(nmhstorage)) && *cp)
tmp = concat(cp, "/", invo_name, NULL);
else
if ((cp = context_find(nmhstorage)) && *cp)
tmp = concat(cp, "/", invo_name, NULL);
else
- tmp = getcpy(toabsdir(invo_name));
+ tmp = mh_xstrdup(toabsdir(invo_name));
/* Check if we have a file to process */
if (!compfile)
/* Check if we have a file to process */
if (!compfile)
@@
-312,25
+313,28
@@
unlink_done()
static CT
build_mime(char *infile)
{
static CT
build_mime(char *infile)
{
- int compnum, state;
- char buf[BUFSIZ], name[NAMESZ];
+ enum state state;
+ struct field f = {{0}};
+ int compnum;
+ char buf[BUFSIZ];
char *cp, *np, *vp;
struct multipart *m;
struct part **pp;
CT ct;
FILE *in;
char *cp, *np, *vp;
struct multipart *m;
struct part **pp;
CT ct;
FILE *in;
+ HF hp;
umask(~m_gmprot());
/* open the composition draft */
umask(~m_gmprot());
/* open the composition draft */
- if ((in = fopen(infile, "r")) == NULL)
+ if ((in = fopen(infile, "r")) == NULL) {
adios(EX_IOERR, infile, "unable to open for reading");
adios(EX_IOERR, infile, "unable to open for reading");
+ }
/*
** Allocate space for primary (outside) content
*/
/*
** Allocate space for primary (outside) content
*/
- if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ ct = mh_xcalloc(1, sizeof(*ct));
/*
** Allocate structure for handling decoded content
/*
** Allocate structure for handling decoded content
@@
-344,63
+348,45
@@
build_mime(char *infile)
** draft into the linked list of header fields for
** the new MIME message.
*/
** draft into the linked list of header fields for
** the new MIME message.
*/
- for (compnum = 1, state = FLD;;) {
- switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
- case FLD:
- case FLDPLUS:
- case FLDEOF:
+ for (compnum = 1, state = FLD2;;) {
+ switch (state = m_getfld2(state, &f, in)) {
+ case FLD2:
compnum++;
/* abort if draft has Mime-Version header field */
compnum++;
/* abort if draft has Mime-Version header field */
- if (!mh_strcasecmp(name, VRSN_FIELD))
+ if (!mh_strcasecmp(f.name, VRSN_FIELD)) {
adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+ }
/*
** abort if draft has Content-Transfer-Encoding
** header field
*/
/*
** abort if draft has Content-Transfer-Encoding
** header field
*/
- if (!mh_strcasecmp(name, ENCODING_FIELD))
+ if (!mh_strcasecmp(f.name, ENCODING_FIELD)) {
adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
+ }
/* ignore any Content-Type fields in the header */
/* ignore any Content-Type fields in the header */
- if (!mh_strcasecmp(name, TYPE_FIELD)) {
- while (state == FLDPLUS)
- state = m_getfld(state, name, buf,
- sizeof(buf), in);
- goto finish_field;
+ if (!mh_strcasecmp(f.name, TYPE_FIELD)) {
+ continue;
}
}
- /* get copies of the buffers */
- np = getcpy(name);
- vp = getcpy(buf);
+ /* add the header data to the list */
+ add_header(ct, mh_xstrdup(f.name), mh_xstrdup(f.value));
- /* if necessary, get rest of field */
- while (state == FLDPLUS) {
- state = m_getfld(state, name, buf,
- sizeof(buf), in);
- vp = add(buf, vp); /* add to prev value */
- }
-
- /* Now add the header data to the list */
- add_header(ct, np, vp);
+ continue;
-finish_field:
- /* if this wasn't the last hdr field, then continue */
- if (state != FLDEOF)
- continue;
- /* else fall... */
+ case BODY2:
+ fseek(in, (long) (-strlen(f.value)), SEEK_CUR);
+ break;
- case FILEEOF:
+ case FILEEOF2:
adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
/* NOTREACHED */
adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
/* NOTREACHED */
- case BODY:
- case BODYEOF:
- fseek(in, (long) (-strlen(buf)), SEEK_CUR);
- break;
-
- case LENERR:
- case FMTERR:
+ case LENERR2:
+ case FMTERR2:
+ case IOERR2:
adios(EX_CONFIG, NULL, "message format error in component #%d",
compnum);
adios(EX_CONFIG, NULL, "message format error in component #%d",
compnum);
@@
-411,11
+397,9
@@
finish_field:
}
/*
}
/*
- * Iterate through the list of headers and call the function to MIME-ify
- * them if required.
- */
-
- HF hp;
+ ** Iterate through the list of headers and call the function to
+ ** MIME-ify them if required.
+ */
for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
if (encode_rfc2047(hp->name, &hp->value, NULL)) {
adios(EX_DATAERR, NULL, "Unable to encode header \"%s\"", hp->name);
for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
if (encode_rfc2047(hp->name, &hp->value, NULL)) {
adios(EX_DATAERR, NULL, "Unable to encode header \"%s\"", hp->name);
@@
-426,12
+410,12
@@
finish_field:
** Now add the MIME-Version header field
** to the list of header fields.
*/
** Now add the MIME-Version header field
** to the list of header fields.
*/
- np = getcpy(VRSN_FIELD);
+ np = mh_xstrdup(VRSN_FIELD);
vp = concat(" ", VRSN_VALUE, "\n", NULL);
add_header(ct, np, vp);
/*
vp = concat(" ", VRSN_VALUE, "\n", NULL);
add_header(ct, np, vp);
/*
- ** We initally assume we will find multiple contents in the
+ ** We initially assume we will find multiple contents in the
** draft. So create a multipart/mixed content to hold everything.
** We can remove this later, if it is not needed.
*/
** draft. So create a multipart/mixed content to hold everything.
** We can remove this later, if it is not needed.
*/
@@
-440,10
+424,9
@@
finish_field:
}
ct->c_type = CT_MULTIPART;
ct->c_subtype = MULTI_MIXED;
}
ct->c_type = CT_MULTIPART;
ct->c_subtype = MULTI_MIXED;
- ct->c_file = getcpy(infile);
+ ct->c_file = mh_xstrdup(infile);
- if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
@@
-462,8
+445,7
@@
finish_field:
if (!p)
continue;
if (!p)
continue;
- if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ part = mh_xcalloc(1, sizeof(*part));
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
@@
-543,8
+525,7
@@
init_decoded_content(CT ct)
{
CE ce;
{
CE ce;
- if ((ce = (CE) mh_xcalloc(1, sizeof(*ce))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ ce = mh_xcalloc(1, sizeof(*ce));
ct->c_cefile = ce;
ct->c_ceopenfnx = open7Bit; /* since unencoded */
ct->c_cefile = ce;
ct->c_ceopenfnx = open7Bit; /* since unencoded */
@@
-604,8
+585,7
@@
user_content(FILE *in, char *file, char *buf, CT *ctp)
}
/* allocate basic Content structure */
}
/* allocate basic Content structure */
- if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ ct = mh_xcalloc(1, sizeof(*ct));
*ctp = ct;
/* allocate basic structure for handling decoded content */
*ctp = ct;
/* allocate basic structure for handling decoded content */
@@
-636,7
+616,7
@@
user_content(FILE *in, char *file, char *buf, CT *ctp)
adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
/* use a temp file to collect the plain text lines */
adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
/* use a temp file to collect the plain text lines */
- ce->ce_file = getcpy(cp);
+ ce->ce_file = mh_xstrdup(cp);
ce->ce_unlink = 1;
if (buf[0] == '#' && buf[1] == '<') {
ce->ce_unlink = 1;
if (buf[0] == '#' && buf[1] == '<') {
@@
-818,8
+798,8
@@
use_forw:
continue;
if (!*cp)
adios(EX_DATAERR, NULL, "empty pipe command for #%s directive", ci->ci_type);
continue;
if (!*cp)
adios(EX_DATAERR, NULL, "empty pipe command for #%s directive", ci->ci_type);
- cp = getcpy(cp);
- free(ci->ci_magic);
+ cp = mh_xstrdup(cp);
+ mh_free0(&(ci->ci_magic));
ci->ci_magic = cp;
} else {
/* record filename of decoded contents */
ci->ci_magic = cp;
} else {
/* record filename of decoded contents */
@@
-846,7
+826,7
@@
use_forw:
exit(EX_CONFIG);
}
}
exit(EX_CONFIG);
}
}
- ci->ci_magic = getcpy(cp);
+ ci->ci_magic = mh_xstrdup(cp);
return OK;
}
return OK;
}
@@
-881,13
+861,13
@@
use_forw:
if (folder)
adios(EX_USAGE, NULL, "only one folder per #forw directive");
else
if (folder)
adios(EX_USAGE, NULL, "only one folder per #forw directive");
else
- folder = getcpy(expandfol(cp));
+ folder = mh_xstrdup(expandfol(cp));
}
}
/* else, use the current folder */
if (!folder)
}
}
/* else, use the current folder */
if (!folder)
- folder = getcpy(getcurfol());
+ folder = mh_xstrdup(getcurfol());
if (!(mp = folder_read(folder)))
adios(EX_IOERR, NULL, "unable to read folder %s", folder);
if (!(mp = folder_read(folder)))
adios(EX_IOERR, NULL, "unable to read folder %s", folder);
@@
-897,7
+877,7
@@
use_forw:
if (!m_convert(mp, cp))
exit(EX_USAGE);
}
if (!m_convert(mp, cp))
exit(EX_USAGE);
}
- free(folder);
+ mh_free0(&folder);
free_ctinfo(ct);
/*
free_ctinfo(ct);
/*
@@
-913,9
+893,7
@@
use_forw:
ct->c_type = CT_MULTIPART;
ct->c_subtype = MULTI_DIGEST;
ct->c_type = CT_MULTIPART;
ct->c_subtype = MULTI_DIGEST;
- if ((m = (struct multipart *)
- mh_xcalloc(1, sizeof(*m))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ m = mh_xcalloc(1, sizeof(*m));
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
@@
-925,9
+903,7
@@
use_forw:
CT p;
CE pe;
CT p;
CE pe;
- if ((p = (CT) mh_xcalloc(1, sizeof(*p)))
- == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ p = mh_xcalloc(1, sizeof(*p));
init_decoded_content(p);
pe = p->c_cefile;
if (get_ctinfo("message/rfc822", p, 0)
init_decoded_content(p);
pe = p->c_cefile;
if (get_ctinfo("message/rfc822", p, 0)
@@
-939,10
+915,9
@@
use_forw:
snprintf(buffer, sizeof(buffer),
"%s/%d", mp->foldpath,
msgnum);
snprintf(buffer, sizeof(buffer),
"%s/%d", mp->foldpath,
msgnum);
- pe->ce_file = getcpy(buffer);
+ pe->ce_file = mh_xstrdup(buffer);
- if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ part = mh_xcalloc(1, sizeof(*part));
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
@@
-958,7
+933,7
@@
use_forw:
msgnum = mp->lowsel;
snprintf(buffer, sizeof(buffer), "%s/%d",
mp->foldpath, msgnum);
msgnum = mp->lowsel;
snprintf(buffer, sizeof(buffer), "%s/%d",
mp->foldpath, msgnum);
- ce->ce_file = getcpy(buffer);
+ ce->ce_file = mh_xstrdup(buffer);
}
folder_free(mp); /* free folder/message structure */
}
folder_free(mp); /* free folder/message structure */
@@
-1001,8
+976,7
@@
use_forw:
ct->c_type = CT_MULTIPART;
ct->c_subtype = vrsn;
ct->c_type = CT_MULTIPART;
ct->c_subtype = vrsn;
- if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ m = mh_xcalloc(1, sizeof(*m));
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
@@
-1018,9
+992,7
@@
use_forw:
if (!p)
continue;
if (!p)
continue;
- if ((part = (struct part *)
- mh_xcalloc(1, sizeof(*part))) == NULL)
- adios(EX_OSERR, NULL, "out of memory");
+ part = mh_xcalloc(1, sizeof(*part));
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
*pp = part;
pp = &part->mp_next;
part->mp_part = p;
@@
-1050,10
+1022,10
@@
set_id(CT ct, int top)
snprintf(msgid, sizeof(msgid), "<%d.%ld.%%d@%s>\n",
(int) getpid(), (long) clock, LocalName());
partno = 0;
snprintf(msgid, sizeof(msgid), "<%d.%ld.%%d@%s>\n",
(int) getpid(), (long) clock, LocalName());
partno = 0;
- msgfmt = getcpy(msgid);
+ msgfmt = mh_xstrdup(msgid);
}
snprintf(msgid, sizeof(msgid), msgfmt, top ? 0 : ++partno);
}
snprintf(msgid, sizeof(msgid), msgfmt, top ? 0 : ++partno);
- ct->c_id = getcpy(msgid);
+ ct->c_id = mh_xstrdup(msgid);
}
}
@@
-1091,7
+1063,7
@@
compose_content(CT ct)
CT p = part->mp_part;
sprintf(pp, "%d", partnum);
CT p = part->mp_part;
sprintf(pp, "%d", partnum);
- p->c_partno = getcpy(partnam);
+ p->c_partno = mh_xstrdup(partnam);
if (compose_content(p) == NOTOK)
return NOTOK;
}
if (compose_content(p) == NOTOK)
return NOTOK;
}
@@
-1122,7
+1094,7
@@
compose_content(CT ct)
if (tfile == NULL) {
adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
}
if (tfile == NULL) {
adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
}
- ce->ce_file = getcpy(tfile);
+ ce->ce_file = mh_xstrdup(tfile);
ce->ce_unlink = 1;
xstdout = 0;
ce->ce_unlink = 1;
xstdout = 0;
@@
-1305,13
+1277,8
@@
scan_content(CT ct)
case CT_TEXT:
check8bit = 1;
checkboundary = 1;
case CT_TEXT:
check8bit = 1;
checkboundary = 1;
- if (ct->c_subtype == TEXT_PLAIN) {
- checklinelen = 0;
- checklinespace = 0;
- } else {
- checklinelen = 1;
- checklinespace = 1;
- }
+ checklinelen = 1;
+ checklinespace = 1;
break;
case CT_MESSAGE:
break;
case CT_MESSAGE:
@@
-1409,7
+1376,7
@@
scan_content(CT ct)
NULL);
} else {
t->tx_charset = CHARSET_USASCII;
NULL);
} else {
t->tx_charset = CHARSET_USASCII;
- *ap = getcpy("charset=us-ascii");
+ *ap = mh_xstrdup("charset=us-ascii");
}
cp = strchr(*ap++, '=');
}
cp = strchr(*ap++, '=');
@@
-1471,7
+1438,7
@@
build_headers(CT ct)
ep = ci->ci_values;
snprintf(buffer, sizeof(buffer), "boundary=%s%d",
prefix, level++);
ep = ci->ci_values;
snprintf(buffer, sizeof(buffer), "boundary=%s%d",
prefix, level++);
- cp = strchr(*ap++ = getcpy(buffer), '=');
+ cp = strchr(*ap++ = mh_xstrdup(buffer), '=');
*ap = NULL;
*cp++ = '\0';
*ep = cp;
*ap = NULL;
*cp++ = '\0';
*ep = cp;
@@
-1480,7
+1447,7
@@
build_headers(CT ct)
/*
** output the content type and subtype
*/
/*
** output the content type and subtype
*/
- np = getcpy(TYPE_FIELD);
+ np = mh_xstrdup(TYPE_FIELD);
vp = concat(" ", ci->ci_type, "/", ci->ci_subtype, NULL);
/* keep track of length of line */
vp = concat(" ", ci->ci_type, "/", ci->ci_subtype, NULL);
/* keep track of length of line */
@@
-1530,7
+1497,7
@@
build_headers(CT ct)
** output the Content-ID
*/
if (ct->c_id) {
** output the Content-ID
*/
if (ct->c_id) {
- np = getcpy(ID_FIELD);
+ np = mh_xstrdup(ID_FIELD);
vp = concat(" ", ct->c_id, NULL);
add_header(ct, np, vp);
}
vp = concat(" ", ct->c_id, NULL);
add_header(ct, np, vp);
}
@@
-1539,7
+1506,7
@@
build_headers(CT ct)
** output the Content-Description
*/
if (ct->c_descr) {
** output the Content-Description
*/
if (ct->c_descr) {
- np = getcpy(DESCR_FIELD);
+ np = mh_xstrdup(DESCR_FIELD);
vp = concat(" ", ct->c_descr, NULL);
if (encode_rfc2047(DESCR_FIELD, &vp, NULL)) {
adios(EX_DATAERR, NULL, "Unable to encode %s header", DESCR_FIELD);
vp = concat(" ", ct->c_descr, NULL);
if (encode_rfc2047(DESCR_FIELD, &vp, NULL)) {
adios(EX_DATAERR, NULL, "Unable to encode %s header", DESCR_FIELD);
@@
-1551,7
+1518,7
@@
build_headers(CT ct)
** output the Content-Disposition
*/
if (ct->c_dispo) {
** output the Content-Disposition
*/
if (ct->c_dispo) {
- np = getcpy(DISPO_FIELD);
+ np = mh_xstrdup(DISPO_FIELD);
vp = concat(" ", ct->c_dispo, NULL);
add_header(ct, np, vp);
}
vp = concat(" ", ct->c_dispo, NULL);
add_header(ct, np, vp);
}
@@
-1568,7
+1535,7
@@
build_headers(CT ct)
if (ct->c_type == CT_MESSAGE)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
if (ct->c_type == CT_MESSAGE)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
- np = getcpy(ENCODING_FIELD);
+ np = mh_xstrdup(ENCODING_FIELD);
vp = concat(" ", "8bit", "\n", NULL);
add_header(ct, np, vp);
break;
vp = concat(" ", "8bit", "\n", NULL);
add_header(ct, np, vp);
break;
@@
-1577,7
+1544,7
@@
build_headers(CT ct)
if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
- np = getcpy(ENCODING_FIELD);
+ np = mh_xstrdup(ENCODING_FIELD);
vp = concat(" ", "quoted-printable", "\n", NULL);
add_header(ct, np, vp);
break;
vp = concat(" ", "quoted-printable", "\n", NULL);
add_header(ct, np, vp);
break;
@@
-1586,7
+1553,7
@@
build_headers(CT ct)
if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
- np = getcpy(ENCODING_FIELD);
+ np = mh_xstrdup(ENCODING_FIELD);
vp = concat(" ", "base64", "\n", NULL);
add_header(ct, np, vp);
break;
vp = concat(" ", "base64", "\n", NULL);
add_header(ct, np, vp);
break;
@@
-1595,7
+1562,7
@@
build_headers(CT ct)
if (ct->c_type == CT_MESSAGE)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
if (ct->c_type == CT_MESSAGE)
adios(EX_DATAERR, NULL, "internal error, invalid encoding");
- np = getcpy(ENCODING_FIELD);
+ np = mh_xstrdup(ENCODING_FIELD);
vp = concat(" ", "binary", "\n", NULL);
add_header(ct, np, vp);
break;
vp = concat(" ", "binary", "\n", NULL);
add_header(ct, np, vp);
break;