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;
+ HF hp;
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");
+ }
/*
** Allocate space for primary (outside) content
*/
- if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
+ if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL) {
adios(EX_OSERR, NULL, "out of memory");
+ }
/*
** Allocate structure for handling decoded content
** 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 */
- 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);
+ }
/*
** 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);
+ }
/* 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, getcpy(f.name), getcpy(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 */
- case BODY:
- case BODYEOF:
- fseek(in, (long) (-strlen(buf)), SEEK_CUR);
- break;
-
- case LENERR:
- case FMTERR:
+ case LENERR2:
+ case FMTERR2:
+ case ERR2:
adios(EX_CONFIG, NULL, "message format error in component #%d",
compnum);
}
/*
+ ** 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);
+ }
+ }
+
+ /*
** Now add the MIME-Version header field
** to the list of header fields.
*/
ct->c_subtype = MULTI_MIXED;
ct->c_file = getcpy(infile);
- if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
+ if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
if (!p)
continue;
- if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
+ if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
*pp = part;
pp = &part->mp_next;
{
CE ce;
- if ((ce = (CE) calloc(1, sizeof(*ce))) == NULL)
+ if ((ce = (CE) mh_xcalloc(1, sizeof(*ce))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
ct->c_cefile = ce;
}
/* allocate basic Content structure */
- if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
+ if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
*ctp = ct;
ct->c_subtype = MULTI_DIGEST;
if ((m = (struct multipart *)
- calloc(1, sizeof(*m))) == NULL)
+ mh_xcalloc(1, sizeof(*m))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
ct->c_ctparams = (void *) m;
pp = &m->mp_parts;
CT p;
CE pe;
- if ((p = (CT) calloc(1, sizeof(*p)))
+ if ((p = (CT) mh_xcalloc(1, sizeof(*p)))
== NULL)
adios(EX_OSERR, NULL, "out of memory");
init_decoded_content(p);
msgnum);
pe->ce_file = getcpy(buffer);
- if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
+ if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
*pp = part;
pp = &part->mp_next;
ct->c_type = CT_MULTIPART;
ct->c_subtype = vrsn;
- if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
+ if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
ct->c_ctparams = (void *) m;
continue;
if ((part = (struct part *)
- calloc(1, sizeof(*part))) == NULL)
+ mh_xcalloc(1, sizeof(*part))) == NULL)
adios(EX_OSERR, NULL, "out of memory");
*pp = part;
pp = &part->mp_next;
if (ct->c_descr) {
np = getcpy(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);
+ }
add_header(ct, np, vp);
}