aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-07-13 09:42:26 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-07-13 09:42:26 +0000
commit70a2615d616d6c29275cfe836678c03b78f802f4 (patch)
treef55becc5b8e2baf0e904332aa87d526823a5f868 /src
parent3083452938b15891e80313f14be554dd22ce933e (diff)
made the file size of attachments more accurate, and human-readable.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@427 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r--src/mimeview.c6
-rw-r--r--src/procmime.c30
-rw-r--r--src/procmime.h1
-rw-r--r--src/textview.c10
4 files changed, 39 insertions, 8 deletions
diff --git a/src/mimeview.c b/src/mimeview.c
index 5b0621bf..6c2d0ee6 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -497,7 +497,7 @@ static gboolean mimeview_append_part(MimeView *mimeview, MimeInfo *partinfo,
gchar *name;
mime_type = partinfo->content_type ? partinfo->content_type : "";
- size = to_human_readable(partinfo->size);
+ size = to_human_readable(partinfo->content_size);
name = get_part_name(partinfo);
gtk_tree_store_append(mimeview->store, iter, parent);
@@ -621,10 +621,10 @@ static void mimeview_show_mime_part(MimeView *mimeview, MimeInfo *partinfo)
g_snprintf(buf, sizeof(buf), "[%s %s (%d bytes)]\n\n",
partinfo->filename ? partinfo->filename :
partinfo->name,
- partinfo->content_type, partinfo->size);
+ partinfo->content_type, partinfo->content_size);
else
g_snprintf(buf, sizeof(buf), "[%s (%d bytes)]\n\n",
- partinfo->content_type, partinfo->size);
+ partinfo->content_type, partinfo->content_size);
gtk_text_buffer_insert(buffer, &iter, buf, -1);
vbbox = gtk_vbutton_box_new();
diff --git a/src/procmime.c b/src/procmime.c
index b94bdeef..bc16e3b4 100644
--- a/src/procmime.c
+++ b/src/procmime.c
@@ -197,7 +197,10 @@ MimeInfo *procmime_scan_message(MsgInfo *msginfo)
#endif
if (mimeinfo) {
- mimeinfo->size = get_left_file_size(fp);
+ mimeinfo->size = msginfo->size;
+ mimeinfo->content_size = get_left_file_size(fp);
+ if (mimeinfo->encoding_type == ENC_BASE64)
+ mimeinfo->content_size = mimeinfo->content_size / 4 * 3;
if (mimeinfo->mime_type == MIME_MULTIPART ||
mimeinfo->mime_type == MIME_MESSAGE_RFC822)
procmime_scan_multipart_message(mimeinfo, fp);
@@ -248,17 +251,23 @@ void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
for (;;) {
MimeInfo *partinfo;
gboolean eom = FALSE;
+ glong content_pos;
+ gboolean is_base64;
gint len;
+ guint b64_content_len = 0;
+ gint b64_pad_len = 0;
prev_fpos = fpos;
debug_print("prev_fpos: %ld\n", fpos);
+ /* scan part header */
if (mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
MimeInfo *sub;
mimeinfo->sub = sub = procmime_scan_mime_header(fp);
if (!sub) break;
+ debug_print("message/rfc822 part found\n");
sub->level = mimeinfo->level + 1;
sub->parent = mimeinfo->parent;
sub->main = mimeinfo;
@@ -272,6 +281,10 @@ void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
partinfo->content_type);
}
+ /* begin content */
+ content_pos = ftell(fp);
+ debug_print("content_pos: %ld\n", content_pos);
+
if (partinfo->mime_type == MIME_MULTIPART ||
partinfo->mime_type == MIME_MESSAGE_RFC822) {
if (partinfo->level < 8)
@@ -280,12 +293,20 @@ void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
/* look for next boundary */
buf[0] = '\0';
+ is_base64 = partinfo->encoding_type == ENC_BASE64;
while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
if (IS_BOUNDARY(buf, boundary, boundary_len)) {
if (buf[2 + boundary_len] == '-' &&
buf[2 + boundary_len + 1] == '-')
eom = TRUE;
break;
+ } else if (is_base64) {
+ const gchar *s;
+ for (s = buf; *s && *s != '\r' && *s != '\n';
+ ++s)
+ if (*s == '=')
+ ++b64_pad_len;
+ b64_content_len += s - buf;
}
}
if (p == NULL) {
@@ -300,7 +321,14 @@ void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
len = strlen(buf);
partinfo->size = fpos - prev_fpos - len;
+ if (is_base64)
+ partinfo->content_size =
+ b64_content_len / 4 * 3 - b64_pad_len;
+ else
+ partinfo->content_size = fpos - content_pos - len;
debug_print("partinfo->size: %d\n", partinfo->size);
+ debug_print("partinfo->content_size: %d\n",
+ partinfo->content_size);
if (partinfo->sub && !partinfo->sub->sub &&
!partinfo->sub->children) {
partinfo->sub->size =
diff --git a/src/procmime.h b/src/procmime.h
index 19ccb2a4..fc2085a9 100644
--- a/src/procmime.h
+++ b/src/procmime.h
@@ -99,6 +99,7 @@ struct _MimeInfo
glong fpos;
guint size;
+ guint content_size;
MimeInfo *main;
MimeInfo *sub;
diff --git a/src/textview.c b/src/textview.c
index 2123f8ba..a0332c84 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -620,13 +620,15 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
else
#endif
if (mimeinfo->filename || mimeinfo->name)
- g_snprintf(buf, sizeof(buf), "\n[%s %s (%d bytes)]\n",
+ g_snprintf(buf, sizeof(buf), "\n[%s %s (%s)]\n",
mimeinfo->filename ? mimeinfo->filename :
mimeinfo->name,
- mimeinfo->content_type, mimeinfo->size);
+ mimeinfo->content_type,
+ to_human_readable(mimeinfo->content_size));
else
- g_snprintf(buf, sizeof(buf), "\n[%s (%d bytes)]\n",
- mimeinfo->content_type, mimeinfo->size);
+ g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n",
+ mimeinfo->content_type,
+ to_human_readable(mimeinfo->content_size));
#if USE_GPGME
if (mimeinfo->sigstatus) {