diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-09-22 11:18:22 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-09-22 11:18:22 +0000 |
commit | e804cac393c2dd84a8c570541fec5d6f7245d945 (patch) | |
tree | a0480475e799431680bfac040b30d30a0b41aeac /libsylph | |
parent | 39a1d4cf0bd2ae39c2300b12f9c826514acd560e (diff) |
implemented 'Save all'.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@601 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/procmime.c | 53 | ||||
-rw-r--r-- | libsylph/procmime.h | 3 | ||||
-rw-r--r-- | libsylph/utils.c | 19 | ||||
-rw-r--r-- | libsylph/utils.h | 5 |
4 files changed, 80 insertions, 0 deletions
diff --git a/libsylph/procmime.c b/libsylph/procmime.c index a9b93a99..7c2105b6 100644 --- a/libsylph/procmime.c +++ b/libsylph/procmime.c @@ -697,6 +697,59 @@ gint procmime_get_part_fp(const gchar *outfile, FILE *infp, MimeInfo *mimeinfo) return 0; } +gint procmime_get_all_parts(const gchar *dir, const gchar *infile, + MimeInfo *mimeinfo) +{ + FILE *fp; + MimeInfo *partinfo; + gchar *base, *filename; + + g_return_val_if_fail(dir != NULL, -1); + g_return_val_if_fail(infile != NULL, -1); + g_return_val_if_fail(mimeinfo != NULL, -1); + + if (!is_dir_exist(dir)) { + g_warning("%s: directory not exist.\n", dir); + return -1; + } + + if ((fp = g_fopen(infile, "rb")) == NULL) { + FILE_OP_ERROR(infile, "fopen"); + return -1; + } + + for (partinfo = mimeinfo; partinfo != NULL; + partinfo = procmime_mimeinfo_next(partinfo)) { + if (partinfo->filename || partinfo->name) { + gint count = 1; + + base = procmime_get_part_file_name(partinfo); + filename = g_strconcat(dir, G_DIR_SEPARATOR_S, base, + NULL); + + while (is_file_entry_exist(filename)) { + gchar *base_alt; + + base_alt = get_alt_filename(base, count++); + g_free(filename); + filename = g_strconcat + (dir, G_DIR_SEPARATOR_S, base_alt, + NULL); + g_free(base_alt); + } + + procmime_get_part_fp(filename, fp, partinfo); + + g_free(filename); + g_free(base); + } + } + + fclose(fp); + + return 0; +} + FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp, const gchar *encoding) { diff --git a/libsylph/procmime.h b/libsylph/procmime.h index b0697f62..722bc88f 100644 --- a/libsylph/procmime.h +++ b/libsylph/procmime.h @@ -159,6 +159,9 @@ gint procmime_get_part (const gchar *outfile, gint procmime_get_part_fp (const gchar *outfile, FILE *infp, MimeInfo *mimeinfo); +gint procmime_get_all_parts (const gchar *dir, + const gchar *infile, + MimeInfo *mimeinfo); FILE *procmime_get_text_content (MimeInfo *mimeinfo, FILE *infp, const gchar *encoding); diff --git a/libsylph/utils.c b/libsylph/utils.c index 5c0ba893..7164ed5c 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -1045,6 +1045,25 @@ void subst_for_filename(gchar *str) subst_chars(str, " \t\r\n\"'/\\", '_'); } +gchar *get_alt_filename(const gchar *filename, gint count) +{ + const gchar *ext; + gchar *alt_filename; + + ext = strrchr(filename, '.'); + + if (ext) { + gchar *base; + + base = g_strndup(filename, ext - filename); + alt_filename = g_strdup_printf("%s-%d%s", base, count, ext); + g_free(base); + } else + alt_filename = g_strdup_printf("%s-%d", filename, count); + + return alt_filename; +} + gboolean is_header_line(const gchar *str) { if (str[0] == ':') return FALSE; diff --git a/libsylph/utils.h b/libsylph/utils.h index 41760bb5..7796541b 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -300,8 +300,13 @@ void subst_null (gchar *str, gint len, gchar subst); void subst_for_filename (gchar *str); + +gchar *get_alt_filename (const gchar *filename, + gint count); + gboolean is_header_line (const gchar *str); gboolean is_ascii_str (const gchar *str); + gint get_quote_level (const gchar *str); gint check_line_length (const gchar *str, gint max_chars, |