static char prefix[] = "----- =_aaaaaaaaaa";
+/*
+ * Maximum size of URL token in message/external-body
+ */
+
+#define MAXURLTOKEN 40
+
/* mhmisc.c */
void content_error (char *, CT, char *, ...);
int find_cache (CT, int, int *, char *, char *, int);
/* mhfree.c */
-void free_content (CT);
void free_ctinfo (CT);
void free_encoding (CT, int);
static int
init_decoded_content (CT ct)
{
- CE ce;
-
- if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL)
- adios (NULL, "out of memory");
-
- ct->c_cefile = ce;
ct->c_ceopenfnx = open7Bit; /* since unencoded */
ct->c_ceclosefnx = close_encoding;
ct->c_cesizefnx = NULL; /* since unencoded */
/* allocate basic structure for handling decoded content */
init_decoded_content (ct);
- ce = ct->c_cefile;
+ ce = &ct->c_cefile;
ci = &ct->c_ctinfo;
set_id (ct, 0);
if (!folder)
folder = add (getfolder (1), NULL);
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 0)))
adios (NULL, "unable to read folder %s", folder);
for (ap = arguments; *ap; ap++) {
cp = *ap;
if ((p = (CT) calloc (1, sizeof(*p))) == NULL)
adios (NULL, "out of memory");
init_decoded_content (p);
- pe = p->c_cefile;
+ pe = &p->c_cefile;
if (get_ctinfo ("message/rfc822", p, 0) == NOTOK)
done (1);
p->c_type = CT_MESSAGE;
static int
compose_content (CT ct)
{
- CE ce = ct->c_cefile;
+ CE ce = &ct->c_cefile;
switch (ct->c_type) {
case CT_MULTIPART:
char *cp = NULL, buffer[BUFSIZ];
struct text *t = NULL;
FILE *in = NULL;
- CE ce = ct->c_cefile;
+ CE ce = &ct->c_cefile;
/*
* handle multipart by scanning all subparts
static int
build_headers (CT ct)
{
- int cc, mailbody, len;
+ int cc, mailbody, extbody, len;
char **ap, **ep;
char *np, *vp, buffer[BUFSIZ];
CI ci = &ct->c_ctinfo;
len = strlen (TYPE_FIELD) + strlen (ci->ci_type)
+ strlen (ci->ci_subtype) + 3;
- mailbody = ct->c_type == CT_MESSAGE
- && ct->c_subtype == MESSAGE_EXTERNAL
- && ((struct exbody *) ct->c_ctparams)->eb_body;
+ extbody = ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_EXTERNAL;
+ mailbody = extbody && ((struct exbody *) ct->c_ctparams)->eb_body;
/*
* Append the attribute/value pairs to
vp = add (";", vp);
len++;
+ /*
+ * According to RFC 2017, if we have a URL longer than 40 characters
+ * we have to break it across multiple lines
+ */
+
+ if (extbody && mh_strcasecmp (*ap, "url") == 0) {
+ char *value = *ep;
+
+ /* 7 here refers to " url=\"\"" */
+ if (len + 1 + (cc = (min(MAXURLTOKEN, strlen(value)) + 7)) >=
+ CPERLIN) {
+ vp = add ("\n\t", vp);
+ len = 8;
+ } else {
+ vp = add (" ", vp);
+ len++;
+ }
+
+ vp = add ("url=\"", vp);
+ len += 5;
+
+ while (strlen(value) > MAXURLTOKEN) {
+ strncpy(buffer, value, MAXURLTOKEN);
+ buffer[MAXURLTOKEN] = '\0';
+ vp = add (buffer, vp);
+ vp = add ("\n\t", vp);
+ value += MAXURLTOKEN;
+ len = 8;
+ }
+
+ vp = add (value, vp);
+ vp = add ("\"", vp);
+ len += strlen(value) + 1;
+ continue;
+ }
+
snprintf (buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep);
if (len + 1 + (cc = strlen (buffer)) >= CPERLIN) {
vp = add ("\n\t", vp);
unsigned char digest[16];
unsigned char outbuf[25];
MD5_CTX mdContext;
- CE ce = ct->c_cefile;
+ CE ce = &ct->c_cefile;
char *infilename = ce->ce_file ? ce->ce_file : ct->c_file;
FILE *in;