diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-11-30 07:44:59 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-11-30 07:44:59 +0000 |
commit | a07a513dcca1b9a8a90499658a27a528660ade40 (patch) | |
tree | 405e2051422fd1b7a3e8a71a65d2e30ba56b5664 /libsylph/procmsg.c | |
parent | 4cc3707180ec49e18d83fd72c4f3eea541eb40ea (diff) |
implemented printing of MIME part. Code cleanups.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1386 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/procmsg.c')
-rw-r--r-- | libsylph/procmsg.c | 100 |
1 files changed, 74 insertions, 26 deletions
diff --git a/libsylph/procmsg.c b/libsylph/procmsg.c index 3d69f015..03f31da5 100644 --- a/libsylph/procmsg.c +++ b/libsylph/procmsg.c @@ -1320,16 +1320,52 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file) return 0; } +static guint print_id = 0; + +static gint print_command_exec(const gchar *file, const gchar *cmdline) +{ + static const gchar *def_cmd = "lpr %s"; + gchar buf[1024]; + +#ifdef G_OS_WIN32 + if (canonicalize_file_replace(file) < 0) + return -1; +#endif + + if (cmdline && str_find_format_times(cmdline, 's') == 1) + g_snprintf(buf, sizeof(buf) - 1, cmdline, file); + else { + if (cmdline) { + g_warning(_("Print command line is invalid: `%s'\n"), + cmdline); + return -1; + } + +#ifdef G_OS_WIN32 + execute_print_file(file); + return 0; +#else + g_snprintf(buf, sizeof(buf) - 1, def_cmd, file); +#endif + } + + g_strchomp(buf); + if (buf[strlen(buf) - 1] != '&') + strcat(buf, "&"); + + system(buf); + + return 0; +} + void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline, gboolean all_headers) { - static const gchar *def_cmd = "lpr %s"; - static guint id = 0; gchar *prtmp; FILE *msgfp, *tmpfp, *prfp; GPtrArray *headers; gint i; - gchar buf[1024]; + gchar buf[BUFFSIZE]; g_return_if_fail(msginfo != NULL); @@ -1340,7 +1376,8 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline, } prtmp = g_strdup_printf("%s%cprinttmp-%08x.txt", - get_mime_tmp_dir(), G_DIR_SEPARATOR, id++); + get_mime_tmp_dir(), G_DIR_SEPARATOR, + print_id++); if ((prfp = g_fopen(prtmp, "wb")) == NULL) { FILE_OP_ERROR(prtmp, "fopen"); @@ -1409,37 +1446,48 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline, fclose(prfp); fclose(tmpfp); -#ifdef G_OS_WIN32 - if (canonicalize_file_replace(prtmp) < 0) { - g_free(prtmp); + print_command_exec(prtmp, cmdline); + + g_free(prtmp); +} + +void procmsg_print_message_part(MsgInfo *msginfo, MimeInfo *partinfo, + const gchar *cmdline, gboolean all_headers) +{ + FILE *msgfp, *tmpfp, *prfp; + gchar *prtmp; + gchar buf[BUFFSIZE]; + + if ((msgfp = procmsg_open_message(msginfo)) == NULL) { return; } -#endif - if (cmdline && str_find_format_times(cmdline, 's') == 1) - g_snprintf(buf, sizeof(buf) - 1, cmdline, prtmp); - else { - if (cmdline) { - g_warning(_("Print command line is invalid: `%s'\n"), - cmdline); - g_free(prtmp); - return; - } + if ((tmpfp = procmime_get_text_content + (partinfo, msgfp, conv_get_locale_charset_str())) == NULL) { + fclose(msgfp); + return; + } + fclose(msgfp); -#ifdef G_OS_WIN32 - execute_print_file(prtmp); + prtmp = g_strdup_printf("%s%cprinttmp-%08x.txt", + get_mime_tmp_dir(), G_DIR_SEPARATOR, + print_id++); + if ((prfp = g_fopen(prtmp, "wb")) == NULL) { + FILE_OP_ERROR(prtmp, "fopen"); g_free(prtmp); + fclose(tmpfp); return; -#else - g_snprintf(buf, sizeof(buf) - 1, def_cmd, prtmp); -#endif } - g_free(prtmp); + while (fgets(buf, sizeof(buf), tmpfp) != NULL) + fputs(buf, prfp); - g_strchomp(buf); - if (buf[strlen(buf) - 1] != '&') strcat(buf, "&"); - system(buf); + fclose(prfp); + fclose(tmpfp); + + print_command_exec(prtmp, cmdline); + + g_free(prtmp); } MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo) |