switch (mimeinfo->content) {
case MIMECONTENT_FILE:
if (mimeinfo->tmp)
- g_unlink(mimeinfo->data.filename);
+ claws_unlink(mimeinfo->data.filename);
g_free(mimeinfo->data.filename);
break;
stat(tmpfilename, &statbuf);
if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
- g_unlink(mimeinfo->data.filename);
+ claws_unlink(mimeinfo->data.filename);
g_free(mimeinfo->data.filename);
mimeinfo->data.filename = tmpfilename;
mimeinfo->tmp = TRUE;
}
if ((tmp_fp = g_fopen(tmp_file, "rb")) == NULL) {
FILE_OP_ERROR(tmp_file, "fopen");
- g_unlink(tmp_file);
+ claws_unlink(tmp_file);
g_free(tmp_file);
fclose(infp);
return FALSE;
if (tmp_file) {
fclose(tmp_fp);
- g_unlink(tmp_file);
+ claws_unlink(tmp_file);
g_free(tmp_file);
}
} else if (encoding == ENC_QUOTED_PRINTABLE) {
if (mimeinfo->content == MIMECONTENT_FILE) {
if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
- g_unlink(mimeinfo->data.filename);
+ claws_unlink(mimeinfo->data.filename);
g_free(mimeinfo->data.filename);
} else if (mimeinfo->content == MIMECONTENT_MEM) {
if (mimeinfo->tmp && (mimeinfo->data.mem != NULL))
if (fclose(outfp) == EOF) {
saved_errno = errno;
FILE_OP_ERROR(outfile, "fclose");
- g_unlink(outfile);
+ claws_unlink(outfile);
return -(saved_errno);
}
fclose(tmpfp);
rewind(outfp);
- g_unlink(tmpfile);
+ claws_unlink(tmpfile);
g_free(tmpfile);
if (err == TRUE) {
{
FILE *outfp = NULL;
MimeInfo *mimeinfo, *partinfo;
+ gboolean empty_ok = FALSE, short_scan = TRUE;
START_TIMING("");
g_return_val_if_fail(msginfo != NULL, NULL);
- mimeinfo = procmime_scan_message_short(msginfo);
+ /* first we try to short-scan (for speed), refusing empty parts */
+scan_again:
+ if (short_scan)
+ mimeinfo = procmime_scan_message_short(msginfo);
+ else
+ mimeinfo = procmime_scan_message(msginfo);
if (!mimeinfo) return NULL;
partinfo = mimeinfo;
- while (partinfo && partinfo->type != MIMETYPE_TEXT) {
+ while (partinfo && (partinfo->type != MIMETYPE_TEXT ||
+ (partinfo->length == 0 && !empty_ok))) {
partinfo = procmime_mimeinfo_next(partinfo);
}
if (partinfo)
outfp = procmime_get_text_content(partinfo);
-
+ else if (!empty_ok && short_scan) {
+ /* if short scan didn't find a non-empty part, rescan
+ * fully for non-empty parts
+ */
+ short_scan = FALSE;
+ procmime_mimeinfo_free_all(mimeinfo);
+ goto scan_again;
+ } else if (!empty_ok && !short_scan) {
+ /* if full scan didn't find a non-empty part, rescan
+ * accepting empty parts
+ */
+ empty_ok = TRUE;
+ procmime_mimeinfo_free_all(mimeinfo);
+ goto scan_again;
+ }
procmime_mimeinfo_free_all(mimeinfo);
END_TIMING();
return outfp;
partinfo = mimeinfo;
while (partinfo && partinfo->type != MIMETYPE_TEXT) {
partinfo = procmime_mimeinfo_next(partinfo);
+ if (privacy_mimeinfo_is_signed(partinfo))
+ procmsg_msginfo_set_flags(msginfo, 0, MSG_SIGNED);
}
if (partinfo)
base = g_path_get_basename(filename);
if ((p = strrchr(base, '.')) != NULL)
- Xstrdup_a(ext, p + 1, p = NULL );
+ ext = g_utf8_strdown(p + 1, -1);
g_free(base);
- if (!p) return NULL;
- g_strdown(ext);
mime_type = g_hash_table_lookup(mime_type_table, ext);
+ g_free(ext);
if (mime_type) {
gchar *str;
exts = g_strsplit(mime_type->extension, " ", 16);
for (i = 0; exts[i] != NULL; i++) {
- /* make the key case insensitive */
- g_strdown(exts[i]);
/* use previously dup'd key on overwriting */
if (g_hash_table_lookup(table, exts[i]))
key = exts[i];
if (mime_type_list)
return mime_type_list;
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
if ((fp = g_fopen(DATAROOTDIR "/mime/globs", "rb")) == NULL)
#else
if ((fp = g_fopen("/usr/share/mime/globs", "rb")) == NULL)
}
if (*p)
- mime_type->extension = g_strdup(p);
+ mime_type->extension = g_utf8_strdown(p, -1);
else
mime_type->extension = NULL;
gchar *content_id,
gchar *content_disposition,
gchar *content_location,
+ const gchar *original_msgid,
+ const gchar *disposition_notification_hdr,
const gchar *filename,
guint offset,
guint length,
NULL, TRUE},
{"MIME-Version:",
NULL, TRUE},
+ {"Original-Message-ID:",
+ NULL, TRUE},
+ {"Disposition:",
+ NULL, TRUE},
{NULL, NULL, FALSE}};
guint content_start, i;
FILE *fp;
g_free(hentry[5].body);
hentry[5].body = tmp;
}
+ if (hentry[7].body != NULL) {
+ tmp = conv_unmime_header(hentry[7].body, NULL);
+ g_free(hentry[7].body);
+ hentry[7].body = tmp;
+ }
+ if (hentry[8].body != NULL) {
+ tmp = conv_unmime_header(hentry[8].body, NULL);
+ g_free(hentry[8].body);
+ hentry[8].body = tmp;
+ }
+
content_start = ftell(fp);
fclose(fp);
hentry[0].body, hentry[1].body,
hentry[2].body, hentry[3].body,
hentry[4].body, hentry[5].body,
+ hentry[7].body, hentry[8].body,
mimeinfo->data.filename, content_start,
len, short_scan);
}
}
-static void procmime_parse_disposition_notification(MimeInfo *mimeinfo, gboolean short_scan)
+static void procmime_parse_disposition_notification(MimeInfo *mimeinfo,
+ const gchar *original_msgid, const gchar *disposition_notification_hdr,
+ gboolean short_scan)
{
HeaderEntry hentry[] = {{"Original-Message-ID:", NULL, TRUE},
{"Disposition:", NULL, TRUE},
procmime_decode_content(mimeinfo);
+ debug_print("parse disposition notification\n");
fp = g_fopen(mimeinfo->data.filename, "rb");
if (fp == NULL) {
FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return;
}
fseek(fp, mimeinfo->offset, SEEK_SET);
- procheader_get_header_fields(fp, hentry);
+
+ if (original_msgid && disposition_notification_hdr) {
+ hentry[0].body = g_strdup(original_msgid);
+ hentry[1].body = g_strdup(disposition_notification_hdr);
+ } else {
+ procheader_get_header_fields(fp, hentry);
+ }
if (!hentry[0].body || !hentry[1].body) {
+ debug_print("MsgId %s, Disp %s\n",
+ hentry[0].body ? hentry[0].body:"(nil)",
+ hentry[1].body ? hentry[1].body:"(nil)");
goto bail;
}
}
}
+#define GET_HEADERS() { \
+ procheader_get_header_fields(fp, hentry); \
+ if (hentry[0].body != NULL) { \
+ tmp = conv_unmime_header(hentry[0].body, NULL); \
+ g_free(hentry[0].body); \
+ hentry[0].body = tmp; \
+ } \
+ if (hentry[2].body != NULL) { \
+ tmp = conv_unmime_header(hentry[2].body, NULL); \
+ g_free(hentry[2].body); \
+ hentry[2].body = tmp; \
+ } \
+ if (hentry[4].body != NULL) { \
+ tmp = conv_unmime_header(hentry[4].body, NULL); \
+ g_free(hentry[4].body); \
+ hentry[4].body = tmp; \
+ } \
+ if (hentry[5].body != NULL) { \
+ tmp = conv_unmime_header(hentry[5].body, NULL); \
+ g_free(hentry[5].body); \
+ hentry[5].body = tmp; \
+ } \
+ if (hentry[6].body != NULL) { \
+ tmp = conv_unmime_header(hentry[6].body, NULL); \
+ g_free(hentry[6].body); \
+ hentry[6].body = tmp; \
+ } \
+ if (hentry[7].body != NULL) { \
+ tmp = conv_unmime_header(hentry[7].body, NULL); \
+ g_free(hentry[7].body); \
+ hentry[7].body = tmp; \
+ } \
+}
+
static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan)
{
HeaderEntry hentry[] = {{"Content-Type:", NULL, TRUE},
NULL, TRUE},
{"Content-Location:",
NULL, TRUE},
+ {"Original-Message-ID:",
+ NULL, TRUE},
+ {"Disposition:",
+ NULL, TRUE},
{NULL, NULL, FALSE}};
gchar *p, *tmp;
gchar *boundary;
hentry[0].body, hentry[1].body,
hentry[2].body, hentry[3].body,
hentry[4].body, hentry[5].body,
+ hentry[6].body, hentry[7].body,
mimeinfo->data.filename, lastoffset,
len, short_scan);
if (result == 1 && short_scan) {
done = TRUE;
break;
}
- }
+ }
if (buf[2 + boundary_len] == '-' &&
- buf[2 + boundary_len + 1] == '-')
+ buf[2 + boundary_len + 1] == '-') {
break;
-
+ }
for (i = 0; i < (sizeof hentry / sizeof hentry[0]) ; i++) {
g_free(hentry[i].body);
hentry[i].body = NULL;
}
- procheader_get_header_fields(fp, hentry);
- if (hentry[0].body != NULL) {
- tmp = conv_unmime_header(hentry[0].body, NULL);
- g_free(hentry[0].body);
- hentry[0].body = tmp;
- }
- if (hentry[2].body != NULL) {
- tmp = conv_unmime_header(hentry[2].body, NULL);
- g_free(hentry[2].body);
- hentry[2].body = tmp;
- }
- if (hentry[4].body != NULL) {
- tmp = conv_unmime_header(hentry[4].body, NULL);
- g_free(hentry[4].body);
- hentry[4].body = tmp;
- }
- if (hentry[5].body != NULL) {
- tmp = conv_unmime_header(hentry[5].body, NULL);
- g_free(hentry[5].body);
- hentry[5].body = tmp;
- }
+ GET_HEADERS();
lastoffset = ftell(fp);
}
}
param = params;
next = params;
for (; next != NULL; param = next) {
- gchar *attribute, *value, *tmp;
+ gchar *attribute, *value, *tmp, *down_attr, *orig_down_attr;
gint len;
gboolean convert = FALSE;
while (value[0] == ' ')
value++;
- g_strdown(attribute);
-
- len = strlen(attribute);
- if (attribute[len - 1] == '*') {
+ down_attr = g_utf8_strdown(attribute, -1);
+ orig_down_attr = down_attr;
+
+ len = strlen(down_attr);
+ if (down_attr[len - 1] == '*') {
gchar *srcpos, *dstpos, *endpos;
convert = TRUE;
- attribute[len - 1] = '\0';
+ down_attr[len - 1] = '\0';
srcpos = value;
dstpos = value;
*tmp = '\0';
}
- if (attribute) {
- while (attribute[0] == ' ')
- attribute++;
- while (attribute[strlen(attribute)-1] == ' ')
- attribute[strlen(attribute)-1] = '\0';
+ if (down_attr) {
+ while (down_attr[0] == ' ')
+ down_attr++;
+ while (down_attr[strlen(down_attr)-1] == ' ')
+ down_attr[strlen(down_attr)-1] = '\0';
}
if (value) {
while (value[0] == ' ')
while (value[strlen(value)-1] == ' ')
value[strlen(value)-1] = '\0';
}
- if (strrchr(attribute, '*') != NULL) {
+ if (strrchr(down_attr, '*') != NULL) {
gchar *tmpattr;
- tmpattr = g_strdup(attribute);
+ tmpattr = g_strdup(down_attr);
tmp = strrchr(tmpattr, '*');
tmp[0] = '\0';
if ((tmp[1] == '0') && (tmp[2] == '\0') &&
- (g_slist_find_custom(concatlist, attribute, g_str_equal) == NULL))
+ (g_slist_find_custom(concatlist, down_attr, g_str_equal) == NULL))
concatlist = g_slist_prepend(concatlist, g_strdup(tmpattr));
- if (convert && (g_slist_find_custom(convlist, attribute, g_str_equal) == NULL))
+ if (convert && (g_slist_find_custom(convlist, down_attr, g_str_equal) == NULL))
convlist = g_slist_prepend(convlist, g_strdup(tmpattr));
g_free(tmpattr);
} else if (convert) {
- if (g_slist_find_custom(convlist, attribute, g_str_equal) == NULL)
- convlist = g_slist_prepend(convlist, g_strdup(attribute));
+ if (g_slist_find_custom(convlist, down_attr, g_str_equal) == NULL)
+ convlist = g_slist_prepend(convlist, g_strdup(down_attr));
}
- if (g_hash_table_lookup(table, attribute) == NULL)
- g_hash_table_insert(table, g_strdup(attribute), g_strdup(value));
+ if (g_hash_table_lookup(table, down_attr) == NULL)
+ g_hash_table_insert(table, g_strdup(down_attr), g_strdup(value));
+ g_free(orig_down_attr);
}
for (cur = concatlist; cur != NULL; cur = g_slist_next(cur)) {
}
mimeinfo->type = procmime_get_media_type(type);
- mimeinfo->subtype = g_strdup(subtype);
+ mimeinfo->subtype = g_strstrip(g_strdup(subtype));
/* Get mimeinfo->typeparameters */
if (params != NULL)
gchar *content_id,
gchar *content_disposition,
gchar *content_location,
+ const gchar *original_msgid,
+ const gchar *disposition_notification_hdr,
const gchar *filename,
guint offset,
guint length,
procmime_parse_message_rfc822(mimeinfo, short_scan);
}
if (g_ascii_strcasecmp(mimeinfo->subtype, "disposition-notification") == 0) {
- procmime_parse_disposition_notification(mimeinfo, short_scan);
+ procmime_parse_disposition_notification(mimeinfo,
+ original_msgid, disposition_notification_hdr, short_scan);
}
break;
case MIMETYPE_MULTIPART:
procmime_parse_multipart(mimeinfo, short_scan);
break;
-
+
+ case MIMETYPE_APPLICATION:
+ if (g_ascii_strcasecmp(mimeinfo->subtype, "octet-stream") == 0
+ && original_msgid && *original_msgid
+ && disposition_notification_hdr && *disposition_notification_hdr) {
+ procmime_parse_disposition_notification(mimeinfo,
+ original_msgid, disposition_notification_hdr, short_scan);
+ }
+ break;
default:
break;
}