/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "intl.h"
#include "procmime.h"
#include "procheader.h"
-#include "common/base64.h"
-#include "common/uuencode.h"
+#include "base64.h"
+#include "quoted-printable.h"
+#include "uuencode.h"
#include "unmime.h"
#include "html.h"
#include "enriched.h"
# include "rfc2015.h"
#endif
-#include "prefs.h"
+#include "prefs_gtk.h"
static GHashTable *procmime_get_mime_type_table (void);
g_free(mimeinfo->boundary);
g_free(mimeinfo->content_disposition);
g_free(mimeinfo->filename);
+ g_free(mimeinfo->description);
#if USE_GPGME
g_free(mimeinfo->plaintextfile);
g_free(mimeinfo->sigstatus);
return NULL;
}
+#if 0
+void procmime_dump_mimeinfo(MimeInfo *mimeinfo)
+{
+ gint i;
+
+ g_print("\n");
+
+ for (; mimeinfo != NULL; mimeinfo = procmime_mimeinfo_next(mimeinfo)) {
+ for (i = 0; i < mimeinfo->level; i++)
+ g_print(" ");
+ g_print("%s%s\n", mimeinfo->main ? "sub: " : "",
+ mimeinfo->content_type);
+ }
+}
+#endif
+
MimeInfo *procmime_scan_message(MsgInfo *msginfo)
{
FILE *fp;
g_return_val_if_fail(msginfo != NULL, NULL);
+#if USE_GPGME
+ if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
+ return NULL;
+#else
if ((fp = procmsg_open_message(msginfo)) == NULL) return NULL;
mimeinfo = procmime_scan_mime_header(fp);
+#endif
if (mimeinfo) {
- if (mimeinfo->mime_type != MIME_MULTIPART) {
- if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
- perror("fseek");
- }
- if (mimeinfo->mime_type != MIME_TEXT)
+ mimeinfo->size = get_left_file_size(fp);
+ if (mimeinfo->mime_type == MIME_MULTIPART ||
+ mimeinfo->mime_type == MIME_MESSAGE_RFC822)
procmime_scan_multipart_message(mimeinfo, fp);
}
-#if USE_GPGME
- if (prefs_common.auto_check_signatures)
- rfc2015_check_signature(mimeinfo, fp);
-#endif
fclose(fp);
return mimeinfo;
gint boundary_len = 0;
gchar buf[BUFFSIZE];
glong fpos, prev_fpos;
- gint npart;
g_return_if_fail(mimeinfo != NULL);
- g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
+ g_return_if_fail(mimeinfo->mime_type == MIME_MULTIPART ||
+ mimeinfo->mime_type == MIME_MESSAGE_RFC822);
if (mimeinfo->mime_type == MIME_MULTIPART) {
g_return_if_fail(mimeinfo->boundary != NULL);
while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
if (!p) return;
+ } else if (mimeinfo->parent && mimeinfo->parent->boundary) {
+ boundary = mimeinfo->parent->boundary;
+ boundary_len = strlen(boundary);
}
if ((fpos = ftell(fp)) < 0) {
return;
}
- for (npart = 0;; npart++) {
+ for (;;) {
MimeInfo *partinfo;
gboolean eom = FALSE;
+ gint len;
prev_fpos = fpos;
debug_print("prev_fpos: %ld\n", fpos);
- partinfo = procmime_scan_mime_header(fp);
- if (!partinfo) break;
- procmime_mimeinfo_insert(mimeinfo, partinfo);
-
- if (partinfo->mime_type == MIME_MULTIPART) {
- if (partinfo->level < 8)
- procmime_scan_multipart_message(partinfo, fp);
- } else if (partinfo->mime_type == MIME_MESSAGE_RFC822) {
+ if (mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
MimeInfo *sub;
- partinfo->sub = sub = procmime_scan_mime_header(fp);
+ mimeinfo->sub = sub = procmime_scan_mime_header(fp);
if (!sub) break;
- sub->level = partinfo->level + 1;
- sub->parent = partinfo;
- sub->main = partinfo;
-
- if (sub->level < 8) {
- if (sub->mime_type == MIME_MULTIPART) {
- procmime_scan_multipart_message
- (sub, fp);
- } else if (sub->mime_type == MIME_MESSAGE_RFC822) {
- fseek(fp, sub->fpos, SEEK_SET);
- procmime_scan_multipart_message
- (sub, fp);
- }
- }
+ sub->level = mimeinfo->level + 1;
+ sub->parent = mimeinfo->parent;
+ sub->main = mimeinfo;
+
+ partinfo = sub;
+ } else {
+ partinfo = procmime_scan_mime_header(fp);
+ if (!partinfo) break;
+ procmime_mimeinfo_insert(mimeinfo, partinfo);
+ debug_print("content-type: %s\n",
+ partinfo->content_type);
+ }
+
+ if (partinfo->mime_type == MIME_MULTIPART ||
+ partinfo->mime_type == MIME_MESSAGE_RFC822) {
+ if (partinfo->level < 8)
+ procmime_scan_multipart_message(partinfo, fp);
}
/* look for next boundary */
buf[0] = '\0';
eom = TRUE;
}
+ debug_print("boundary: %s\n", buf);
+
fpos = ftell(fp);
debug_print("fpos: %ld\n", fpos);
- partinfo->size = fpos - prev_fpos - strlen(buf);
+ len = strlen(buf);
+ partinfo->size = fpos - prev_fpos - len;
debug_print("partinfo->size: %d\n", partinfo->size);
if (partinfo->sub && !partinfo->sub->sub &&
!partinfo->sub->children) {
- partinfo->sub->size = fpos - partinfo->sub->fpos - strlen(buf);
+ partinfo->sub->size =
+ fpos - partinfo->sub->fpos - strlen(buf);
debug_print("partinfo->sub->size: %d\n",
partinfo->sub->size);
}
- debug_print("boundary: %s\n", buf);
+
+ if (mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
+ if (len > 0 && fseek(fp, fpos - len, SEEK_SET) < 0)
+ perror("fseek");
+ break;
+ }
if (eom) break;
}
blen = strlen(buf) + 1;
Xalloca(tmp, blen, return);
conv_unmime_header(tmp, blen, buf, NULL);
- g_free(mimeinfo->name);
- mimeinfo->name = NULL;
/*pgp signatures should NOT have a name */
if (mimeinfo->content_type
&& strcasecmp(mimeinfo->content_type, "application/pgp-signature"))
- mimeinfo->name = g_strdup(tmp);
+ mimeinfo->description = g_strdup(tmp);
}
void procmime_scan_subject(MimeInfo *mimeinfo,
}
}
- if (mimeinfo->mime_type == MIME_APPLICATION_OCTET_STREAM &&
- mimeinfo->name) {
- const gchar *type;
- type = procmime_get_mime_type(mimeinfo->name);
- if (type)
- mimeinfo->mime_type = procmime_scan_mime_type(type);
- }
-
if (!mimeinfo->content_type)
mimeinfo->content_type = g_strdup("text/plain");
(!boundary ||
!IS_BOUNDARY(buf, boundary, boundary_len))) {
gint len;
- len = unmime_quoted_printable_line(buf);
+ len = qp_decode_line(buf);
fwrite(buf, len, 1, outfp);
}
} else if (mimeinfo->encoding_type == ENC_BASE64) {
rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
if ((pfile = prefs_write_open(rcpath)) == NULL) {
- g_warning(_("failed to write configuration to file\n"));
+ g_warning("failed to write configuration to file\n");
g_free(rcpath);
return;
}
renderer->renderer);
}
- if (prefs_write_close(pfile) < 0) {
- g_warning(_("failed to write configuration to file\n"));
+ if (prefs_file_close(pfile) < 0) {
+ g_warning("failed to write configuration to file\n");
return;
}
}
dup2(oldout, 1);
} else if (mimeinfo->mime_type == MIME_TEXT) {
while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
- str = conv_codeset_strdup(buf, src_codeset, NULL);
+#warning FIXME_GTK2
+ str = conv_codeset_strdup(buf, src_codeset, CS_UTF_8);
if (str) {
fputs(str, outfp);
g_free(str);
}
if (conv_fail)
- g_warning(_("procmime_get_text_content(): Code conversion failed.\n"));
+ g_warning("procmime_get_text_content(): Code conversion failed.\n");
fclose(tmpfp);
rewind(outfp);
gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo)
{
static guint32 id = 0;
- gchar *base;
+ const gchar *base;
gchar *filename;
gchar f_prefix[10];
if (MIME_TEXT_HTML == mimeinfo->mime_type)
base = "mimetmp.html";
else {
+ gchar *tmp;
base = mimeinfo->filename ? mimeinfo->filename
: mimeinfo->name ? mimeinfo->name : "mimetmp";
base = g_basename(base);
if (*base == '\0') base = "mimetmp";
- Xstrdup_a(base, base, return NULL);
- subst_for_filename(base);
+ Xstrdup_a(tmp, base, return NULL);
+ subst_for_filename(tmp);
+ base = tmp;
}
filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
else if (!strncasecmp(charset, "ISO-2022-", 9) ||
!strcasecmp(charset, "US-ASCII"))
return ENC_7BIT;
+ else if (!strcasecmp(charset, "ISO-8859-5") ||
+ !strncasecmp(charset, "KOI8-", 5) ||
+ !strcasecmp(charset, "Windows-1251"))
+ return ENC_8BIT;
+ else if (!strncasecmp(charset, "ISO-8859-", 9))
+ return ENC_QUOTED_PRINTABLE;
else
return ENC_8BIT;
- /* return ENC_BASE64; */
- /* return ENC_QUOTED_PRINTABLE; */
}
EncodingType procmime_get_encoding_for_file(const gchar *file)