/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto & The Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2016 Hiroyuki Yamamoto & The Claws Mail Team
*
* 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
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
*/
#ifdef HAVE_CONFIG_H
#include "alertpanel.h"
#include "timing.h"
#include "privacy.h"
+#include "account.h"
static GHashTable *procmime_get_mime_type_table (void);
static MimeInfo *procmime_scan_file_short(const gchar *filename);
MimeInfo *mimeinfo;
mimeinfo = g_new0(MimeInfo, 1);
+
mimeinfo->content = MIMECONTENT_EMPTY;
mimeinfo->data.filename = NULL;
return FALSE;
}
-void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
+void procmime_mimeinfo_free_all(MimeInfo **mimeinfo_ptr)
{
+ MimeInfo *mimeinfo = *mimeinfo_ptr;
GNode *node;
if (!mimeinfo)
g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_ALL, -1, free_func, NULL);
g_node_destroy(node);
+
+ *mimeinfo_ptr = NULL;
}
MimeInfo *procmime_mimeinfo_parent(MimeInfo *mimeinfo)
gint llen = 0; \
strretchomp(lastline); \
llen = strlen(lastline); \
- if (lastline[llen-1] == ' ' && strcmp(lastline,"-- ")) { \
+ if (lastline[llen-1] == ' ' && !account_signatures_matchlist_str_found(lastline, "%s") && \
+ !(llen == 2 && lastline[1] == ' ' && strchr(prefs_common.quote_chars, lastline[0]))) { \
/* this is flowed */ \
if (delsp) \
lastline[llen-1] = '\0'; \
gint state = 0;
guint save = 0;
+ cm_return_val_if_fail(mimeinfo != NULL, FALSE);
+
EncodingType encoding = forced_encoding
? forced_encoding
: mimeinfo->encoding_type;
gchar lastline[BUFFSIZE];
memset(lastline, 0, BUFFSIZE);
- cm_return_val_if_fail(mimeinfo != NULL, FALSE);
-
if (prefs_common.respect_flowed_format &&
mimeinfo->type == MIMETYPE_TEXT &&
!strcasecmp(mimeinfo->subtype, "plain")) {
infp = procmime_fopen(mimeinfo->data.filename, "rb");
if (!infp) {
- perror("fopen");
+ FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
return FALSE;
}
if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
- perror("fseek");
+ FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
procmime_fclose(infp);
return FALSE;
}
tmp_file = TRUE;
readend = mimeinfo->offset + mimeinfo->length;
+ account_signatures_matchlist_create(); /* FLUSH_LASTLINE will use it */
+
+ *buf = '\0';
if (encoding == ENC_QUOTED_PRINTABLE) {
while ((ftell(infp) < readend) && (SC_FGETS(buf, sizeof(buf), infp) != NULL)) {
gint len;
len = qp_decode_line(buf);
- buf[len]='\0';
+ buf[len] = '\0';
if (!flowed) {
if (SC_FWRITE(buf, 1, len, outfp) < len)
err = TRUE;
uncanonicalize = TRUE;
tmpfp = my_tmpfile();
if (!tmpfp) {
- perror("tmpfile");
+ perror("my_tmpfile");
if (tmp_file)
procmime_fclose(outfp);
procmime_fclose(infp);
if (SC_FPUTS(buf, outfp) == EOF)
err = TRUE;
}
- procmime_fclose(tmpfp);
}
+ if (tmpfp != outfp)
+ procmime_fclose(tmpfp);
} else if (encoding == ENC_X_UUENCODE) {
gchar outbuf[BUFFSIZE];
gint len;
procmime_fclose(outfp);
procmime_fclose(infp);
+ account_signatures_matchlist_delete();
+
if (err == TRUE) {
return FALSE;
}
return TRUE;
}
-gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
+static gint procmime_get_part_to_stream(FILE *outfp, MimeInfo *mimeinfo)
{
- FILE *infp, *outfp;
+ FILE *infp;
gchar buf[BUFFSIZE];
gint restlength, readlength;
gint saved_errno = 0;
- cm_return_val_if_fail(outfile != NULL, -1);
+ cm_return_val_if_fail(outfp != NULL, -1);
cm_return_val_if_fail(mimeinfo != NULL, -1);
if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
procmime_fclose(infp);
return -(saved_errno);
}
- if ((outfp = procmime_fopen(outfile, "wb")) == NULL) {
- saved_errno = errno;
- FILE_OP_ERROR(outfile, "fopen");
- procmime_fclose(infp);
- return -(saved_errno);
- }
restlength = mimeinfo->length;
if (SC_FWRITE(buf, 1, readlength, outfp) != readlength) {
saved_errno = errno;
procmime_fclose(infp);
- procmime_fclose(outfp);
return -(saved_errno);
}
restlength -= readlength;
}
procmime_fclose(infp);
+ rewind(outfp);
+
+ return 0;
+}
+
+gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
+{
+ FILE *outfp;
+ gint result;
+ gint saved_errno = 0;
+
+ cm_return_val_if_fail(outfile != NULL, -1);
+
+ if ((outfp = procmime_fopen(outfile, "wb")) == NULL) {
+ saved_errno = errno;
+ FILE_OP_ERROR(outfile, "fopen");
+ return -(saved_errno);
+ }
+
+ result = procmime_get_part_to_stream(outfp, mimeinfo);
+
if (procmime_fclose(outfp) == EOF) {
saved_errno = errno;
FILE_OP_ERROR(outfile, "fclose");
return -(saved_errno);
}
- return 0;
+ return result;
}
gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
gboolean conv_fail = FALSE;
gchar buf[BUFFSIZE];
gchar *str;
- gchar *tmpfile;
gboolean scan_ret = FALSE;
+ gchar *tmpfile = NULL;
+ int r;
cm_return_val_if_fail(mimeinfo != NULL, TRUE);
cm_return_val_if_fail(scan_callback != NULL, TRUE);
if (!procmime_decode_content(mimeinfo))
return TRUE;
+#if HAVE_FMEMOPEN
+ tmpfp = fmemopen(NULL, mimeinfo->length * 2, "w+");
+#else
tmpfile = procmime_get_tmp_file_name(mimeinfo);
- if (tmpfile == NULL)
+ if (tmpfile == NULL) {
+ g_warning("no filename\n");
return TRUE;
+ }
+
+ tmpfp = procmime_fopen(tmpfile, "w+");
+#endif
- if (procmime_get_part(tmpfile, mimeinfo) < 0) {
+ if (tmpfp == NULL) {
g_free(tmpfile);
+ FILE_OP_ERROR(tmpfile, "open");
return TRUE;
}
- tmpfp = procmime_fopen(tmpfile, "rb");
- if (tmpfp == NULL) {
+ if ((r = procmime_get_part_to_stream(tmpfp, mimeinfo)) < 0) {
+ g_warning("procmime_get_part_to_stream error %d\n", r);
g_free(tmpfile);
return TRUE;
}
g_warning("procmime_get_text_content(): Code conversion failed.");
procmime_fclose(tmpfp);
+
+#if !HAVE_FMEMOPEN
claws_unlink(tmpfile);
g_free(tmpfile);
+#endif
return scan_ret;
}
gboolean err;
if ((outfp = my_tmpfile()) == NULL) {
- perror("tmpfile");
+ perror("my_tmpfile");
return NULL;
}
#ifdef HAVE_FGETS_UNLOCKED
FILE *procmime_get_binary_content(MimeInfo *mimeinfo)
{
FILE *outfp;
- gchar *tmpfile;
+ gchar *tmpfile = NULL;
cm_return_val_if_fail(mimeinfo != NULL, NULL);
if (!procmime_decode_content(mimeinfo))
return NULL;
+#if HAVE_FMEMOPEN
+ outfp = fmemopen(NULL, mimeinfo->length * 2, "w+");
+#else
tmpfile = procmime_get_tmp_file_name(mimeinfo);
- if (tmpfile == NULL)
- return NULL;
-
- if (procmime_get_part(tmpfile, mimeinfo) < 0) {
- g_free(tmpfile);
- return NULL;
+ if (tmpfile == NULL) {
+ g_warning("no filename\n");
+ return TRUE;
}
- outfp = procmime_fopen(tmpfile, "rb");
- if (outfp == NULL) {
- g_unlink(tmpfile);
- g_free(tmpfile);
- return NULL;
- }
+ outfp = procmime_fopen(tmpfile, "w+");
g_unlink(tmpfile);
g_free(tmpfile);
+#endif
+
+ if (procmime_get_part_to_stream(outfp, mimeinfo) < 0) {
+ return NULL;
+ }
#ifdef HAVE_FGETS_UNLOCKED
funlockfile(outfp);
* fully for non-empty parts
*/
short_scan = FALSE;
- procmime_mimeinfo_free_all(mimeinfo);
+ 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);
+ procmime_mimeinfo_free_all(&mimeinfo);
goto scan_again;
}
- procmime_mimeinfo_free_all(mimeinfo);
+ procmime_mimeinfo_free_all(&mimeinfo);
/* outfp already unlocked at this time */
return outfp;
if (partinfo)
outfp = procmime_get_text_content(partinfo);
- procmime_mimeinfo_free_all(mimeinfo);
+ procmime_mimeinfo_free_all(&mimeinfo);
/* outfp already unlocked at this time */
return outfp;
partinfo = mimeinfo;
result = (find_encrypted_part(partinfo) != NULL);
- procmime_mimeinfo_free_all(mimeinfo);
+ procmime_mimeinfo_free_all(&mimeinfo);
return result;
}
debug_print("got type %s for %s\n", str, ext);
g_free(ext);
return str;
- }
+ }
+ g_free(ext);
return NULL;
#else
gchar *str = get_content_type_from_registry_with_ext(ext);
debug_print("%s %s in %s\n", info?"found":"didn't find", orig_msg_id, outbox->path);
if (info) {
procmsg_msginfo_set_flags(info, MSG_RETRCPT_GOT, 0);
- procmsg_msginfo_free(info);
+ procmsg_msginfo_free(&info);
}
}
}
* this avoids DOSsing ourselves
* with enormous messages
*/
- procmime_mimeinfo_free_all(mimeinfo);
+ procmime_mimeinfo_free_all(&mimeinfo);
return -1;
}
g_node_append(parent->node, mimeinfo->node);
break;
#else
case ENC_AS_EXTENDED:
- debug_print("Unhandled ENC_AS_EXTENDED.");
+ debug_print("Unhandled ENC_AS_EXTENDED.\n");
break;
#endif
case ENC_AS_ENCWORD: