#include "msgcache.h"
#include "partial_download.h"
+static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session);
+
+enum
+{
+ Q_SENDER = 0,
+ Q_SMTPSERVER = 1,
+ Q_RECIPIENTS = 2,
+ Q_NEWSGROUPS = 3,
+ Q_MAIL_ACCOUNT_ID = 4,
+ Q_NEWS_ACCOUNT_ID = 5,
+ Q_SAVE_COPY_FOLDER = 6,
+ Q_REPLY_MESSAGE_ID = 7,
+ Q_FWD_MESSAGE_ID = 8,
+ Q_PRIVACY_SYSTEM = 9,
+ Q_ENCRYPT = 10,
+ Q_ENCRYPT_DATA = 11,
+};
+
GHashTable *procmsg_msg_hash_table_create(GSList *mlist)
{
GHashTable *msg_table;
return filename;
}
+gchar *procmsg_get_message_file_full(MsgInfo *msginfo, gboolean headers, gboolean body)
+{
+ gchar *filename = NULL;
+
+ g_return_val_if_fail(msginfo != NULL, NULL);
+
+ filename = folder_item_fetch_msg_full(msginfo->folder, msginfo->msgnum,
+ headers, body);
+ if (!filename)
+ debug_print("can't fetch message %d\n", msginfo->msgnum);
+
+ return filename;
+}
+
GSList *procmsg_get_message_file_list(GSList *mlist)
{
GSList *file_list = NULL;
SET_FILTER_KEY("header \"List-Id\"", H_LIST_ID);
extract_list_id_str(*key);
} else if (hentry[H_X_SEQUENCE].body != NULL) {
- guchar *p;
+ gchar *p;
SET_FILTER_KEY("X-Sequence", H_X_SEQUENCE);
p = *key;
while (*p != '\0') {
- while (*p != '\0' && !isspace(*p)) p++;
- while (isspace(*p)) p++;
- if (isdigit(*p)) {
+ while (*p != '\0' && !g_ascii_isspace(*p)) p++;
+ while (g_ascii_isspace(*p)) p++;
+ if (g_ascii_isdigit(*p)) {
*p = '\0';
break;
}
GSList *cur;
for (cur = mlist ; cur != NULL ; cur = cur->next) {
MsgInfo * msginfo = (MsgInfo *) cur->data;
- partial_mark_for_delete(msginfo);
+ if (MSG_IS_LOCKED(msginfo->flags))
+ continue;
+ if (msginfo->total_size != 0 &&
+ msginfo->size != (off_t)msginfo->total_size)
+ partial_mark_for_delete(msginfo);
+
procmsg_msginfo_free(msginfo);
}
-
+ g_slist_free(mlist);
folder_item_remove_all_msg(trash);
}
}
GList *cur;
for (cur = folder_get_list(); cur != NULL; cur = cur->next) {
- trash = FOLDER(cur->data)->trash;
+ Folder *folder = FOLDER(cur->data);
+ trash = folder->trash;
procmsg_empty_trash(trash);
+ if (folder->account && folder->account->set_trash_folder &&
+ folder_find_item_from_identifier(folder->account->trash_folder))
+ procmsg_empty_trash(
+ folder_find_item_from_identifier(folder->account->trash_folder));
+ }
+}
+
+static PrefsAccount *procmsg_get_account_from_file(const gchar *file)
+{
+ PrefsAccount *mailac = NULL;
+ FILE *fp;
+ int hnum;
+ gchar buf[BUFFSIZE];
+ static HeaderEntry qentry[] = {{"S:", NULL, FALSE},
+ {"SSV:", NULL, FALSE},
+ {"R:", NULL, FALSE},
+ {"NG:", NULL, FALSE},
+ {"MAID:", NULL, FALSE},
+ {"NAID:", NULL, FALSE},
+ {"SCF:", NULL, FALSE},
+ {"RMID:", NULL, FALSE},
+ {"FMID:", NULL, FALSE},
+ {"X-Sylpheed-Privacy-System:", NULL, FALSE},
+ {"X-Sylpheed-Encrypt:", NULL, FALSE},
+ {"X-Sylpheed-Encrypt-Data:", NULL, FALSE},
+ {NULL, NULL, FALSE}};
+
+ g_return_val_if_fail(file != NULL, NULL);
+
+ if ((fp = fopen(file, "rb")) == NULL) {
+ FILE_OP_ERROR(file, "fopen");
+ return NULL;
+ }
+
+ while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, qentry))
+ != -1) {
+ gchar *p = buf + strlen(qentry[hnum].name);
+
+ if (hnum == Q_MAIL_ACCOUNT_ID) {
+ mailac = account_find_from_id(atoi(p));
+ break;
+ }
+ }
+ fclose(fp);
+ return mailac;
+}
+
+static GSList *procmsg_list_sort_by_account(FolderItem *queue, GSList *list)
+{
+ GSList *result = NULL;
+ GSList *orig = NULL;
+ PrefsAccount *last_account = NULL;
+ MsgInfo *msg = NULL;
+ GSList *cur = NULL;
+ gboolean nothing_to_sort = TRUE;
+
+ if (!list)
+ return NULL;
+
+ orig = g_slist_copy(list);
+
+ msg = (MsgInfo *)orig->data;
+
+ for (cur = orig; cur; cur = cur->next)
+ debug_print("sort before %s\n", ((MsgInfo *)cur->data)->from);
+
+ debug_print("\n");
+
+parse_again:
+ nothing_to_sort = TRUE;
+ cur = orig;
+ while (cur) {
+ gchar *file = NULL;
+ PrefsAccount *ac = procmsg_get_account_from_file(file);
+ msg = (MsgInfo *)cur->data;
+ file = folder_item_fetch_msg(queue, msg->msgnum);
+ g_free(file);
+
+ if (last_account == NULL || (ac != NULL && ac == last_account)) {
+ result = g_slist_append(result, msg);
+ orig = g_slist_remove(orig, msg);
+ last_account = ac;
+ nothing_to_sort = FALSE;
+ goto parse_again;
+ }
+ cur = cur->next;
+ }
+
+ if (orig || g_slist_length(orig)) {
+ if (!last_account && nothing_to_sort) {
+ /* can't find an account for the rest of the list */
+ cur = orig;
+ while (cur) {
+ result = g_slist_append(result, cur->data);
+ cur = cur->next;
+ }
+ } else {
+ last_account = NULL;
+ goto parse_again;
+ }
+ }
+
+ g_slist_free(orig);
+
+ for (cur = result; cur; cur = cur->next)
+ debug_print("sort after %s\n", ((MsgInfo *)cur->data)->from);
+
+ debug_print("\n");
+
+ return result;
+}
+
+static gboolean procmsg_is_last_for_account(FolderItem *queue, MsgInfo *msginfo, GSList *elem)
+{
+ gchar *file = folder_item_fetch_msg(queue, msginfo->msgnum);
+ PrefsAccount *ac = procmsg_get_account_from_file(file);
+ GSList *cur = elem;
+ g_free(file);
+ for (cur = elem; cur; cur = cur->next) {
+ MsgInfo *cur_msginfo = (MsgInfo *)cur->data;
+ file = folder_item_fetch_msg(queue, cur_msginfo->msgnum);
+
+ if (cur_msginfo != msginfo && !MSG_IS_LOCKED(cur_msginfo->flags)) {
+ if (procmsg_get_account_from_file(file) == ac) {
+ g_free(file);
+ return FALSE;
+ }
+ }
+
+ g_free(file);
}
+ return TRUE;
}
/*!
{
gint sent = 0, err = 0;
GSList *list, *elem;
+ GSList *sorted_list = NULL;
if (!queue)
queue = folder_get_default_queue();
folder_item_scan(queue);
list = folder_item_get_msg_list(queue);
- for (elem = list; elem != NULL; elem = elem->next) {
+ /* sort the list per sender account; this helps reusing the same SMTP server */
+ sorted_list = procmsg_list_sort_by_account(queue, list);
+
+ for (elem = sorted_list; elem != NULL; elem = elem->next) {
gchar *file;
MsgInfo *msginfo;
-
+
msginfo = (MsgInfo *)(elem->data);
if (!MSG_IS_LOCKED(msginfo->flags)) {
file = folder_item_fetch_msg(queue, msginfo->msgnum);
if (file) {
- if (procmsg_send_message_queue(file) < 0) {
+ if (procmsg_send_message_queue_full(file,
+ !procmsg_is_last_for_account(queue, msginfo, elem)) < 0) {
g_warning("Sending queued message %d failed.\n",
msginfo->msgnum);
err++;
procmsg_msginfo_free(msginfo);
}
+ g_slist_free(sorted_list);
+
return (err != 0 ? -err : sent);
}
+/*!
+ *\brief Determine if a queue folder is empty
+ *
+ *\param queue Queue folder to process
+ *
+ *\return TRUE if the queue folder is empty, otherwise return FALSE
+ */
+gboolean procmsg_queue_is_empty(FolderItem *queue)
+{
+ GSList *list;
+ gboolean res = FALSE;
+ if (!queue)
+ queue = folder_get_default_queue();
+ g_return_val_if_fail(queue != NULL, TRUE);
+
+ folder_item_scan(queue);
+ list = folder_item_get_msg_list(queue);
+ res = (list == NULL);
+ procmsg_msg_list_free(list);
+ return res;
+}
+
gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
{
FILE *fp, *outfp;
g_return_if_fail(msginfo);
- if ((tmpfp = procmime_get_first_text_content(msginfo)) == NULL) {
+ if (procmime_msginfo_is_encrypted(msginfo))
+ tmpfp = procmime_get_first_encrypted_text_content(msginfo);
+ else
+ tmpfp = procmime_get_first_text_content(msginfo);
+ if (tmpfp == NULL) {
g_warning("Can't get text part\n");
return;
}
g_snprintf(buf, sizeof(buf) - 1, cmdline, prtmp);
else {
if (cmdline)
- g_warning("Print command line is invalid: `%s'\n",
+ g_warning("Print command line is invalid: '%s'\n",
cmdline);
g_snprintf(buf, sizeof(buf) - 1, def_cmd, prtmp);
}
guint procmsg_msginfo_memusage(MsgInfo *msginfo)
{
guint memusage = 0;
+ GSList *refs;
memusage += sizeof(MsgInfo);
if (msginfo->fromname)
memusage += strlen(msginfo->dispositionnotificationto);
if (msginfo->returnreceiptto)
memusage += strlen(msginfo->returnreceiptto);
-#warning FIXME: Calculate size of references list
-#if 0
- if (msginfo->references)
- memusage += strlen(msginfo->references);
-#endif
+ for (refs = msginfo->references; refs; refs=refs->next) {
+ gchar *r = (gchar *)refs->data;
+ memusage += r?strlen(r):0;
+ }
if (msginfo->fromspace)
memusage += strlen(msginfo->fromspace);
return msginfo1->msgnum - msginfo2->msgnum;
}
-enum
-{
- Q_SENDER = 0,
- Q_SMTPSERVER = 1,
- Q_RECIPIENTS = 2,
- Q_NEWSGROUPS = 3,
- Q_MAIL_ACCOUNT_ID = 4,
- Q_NEWS_ACCOUNT_ID = 5,
- Q_SAVE_COPY_FOLDER = 6,
- Q_REPLY_MESSAGE_ID = 7,
- Q_FWD_MESSAGE_ID = 8,
- Q_PRIVACY_SYSTEM = 9,
- Q_ENCRYPT = 10,
- Q_ENCRYPT_DATA = 11,
-};
-
-gint procmsg_send_message_queue(const gchar *file)
+static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session)
{
static HeaderEntry qentry[] = {{"S:", NULL, FALSE},
{"SSV:", NULL, FALSE},
}
if (mailac)
- mailval = send_message_smtp(mailac, to_list, fp);
+ mailval = send_message_smtp_full(mailac, to_list, fp, keep_session);
else {
PrefsAccount tmp_ac;
return (newsval != 0 ? newsval : mailval);
}
+gint procmsg_send_message_queue(const gchar *file)
+{
+ return procmsg_send_message_queue_full(file, FALSE);
+}
+
static void update_folder_msg_counts(FolderItem *item, MsgInfo *msginfo, MsgPermFlags old_flags)
{
MsgPermFlags new_flags = msginfo->flags.perm_flags;
/* MARK flag */
if (!(old_flags & MSG_MARKED) && (new_flags & MSG_MARKED)) {
procmsg_update_unread_children(msginfo, TRUE);
+ item->marked_msgs++;
}
if ((old_flags & MSG_MARKED) && !(new_flags & MSG_MARKED)) {
procmsg_update_unread_children(msginfo, FALSE);
+ item->marked_msgs--;
}
}
if((filtering_rules != NULL) &&
filter_message_by_msginfo(filtering_rules, msginfo))
return TRUE;
+
+ hooks_invoke(MAIL_POSTFILTERING_HOOKLIST, msginfo);
return FALSE;
}
gchar *tmpfile = get_tmp_file();
str_write_to_file(mimeinfo->data.mem, tmpfile);
g_free(mimeinfo->data.mem);
- mimeinfo->content == MIMECONTENT_FILE;
+ mimeinfo->content = MIMECONTENT_FILE;
mimeinfo->data.filename = g_strdup(tmpfile);
g_free(tmpfile);
- }
-
- tmp_msginfo = procheader_parse_file(mimeinfo->data.filename,
- flags, TRUE, FALSE);
-
- if (tmp_msginfo != NULL) {
- tmp_msginfo->folder = src_msginfo->folder;
- tmp_msginfo->plaintext_file = g_strdup(mimeinfo->data.filename);
+ tmp_msginfo = procheader_parse_file(mimeinfo->data.filename,
+ flags, TRUE, FALSE);
+ if (tmp_msginfo != NULL) {
+ tmp_msginfo->folder = src_msginfo->folder;
+ tmp_msginfo->plaintext_file = g_strdup(mimeinfo->data.filename);
+ } else {
+ g_warning("procmsg_msginfo_new_from_mimeinfo(): Can't generate new msginfo");
+ }
} else {
- g_warning("procmsg_msginfo_new_from_mimeinfo(): Can't generate new msginfo");
+ gchar *tmpfile = get_tmp_file();
+ FILE *fp = fopen(tmpfile, "wb");
+ if (fp && procmime_write_message_rfc822(mimeinfo, fp) >= 0) {
+ tmp_msginfo = procheader_parse_file(
+ tmpfile, flags, TRUE, FALSE);
+ }
+ if (fp)
+ fclose(fp);
+ if (tmp_msginfo != NULL) {
+ tmp_msginfo->folder = src_msginfo->folder;
+ tmp_msginfo->plaintext_file = g_strdup(tmpfile);
+ } else {
+ g_warning("procmsg_msginfo_new_from_mimeinfo(): Can't generate new msginfo");
+ }
+ g_free(tmpfile);
+
}
return tmp_msginfo;