/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
*
* 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
#include "alertpanel.h"
#include "news.h"
#include "imap.h"
+#include "hooks.h"
typedef struct _FlagInfo FlagInfo;
static GHashTable *procmsg_read_mark_file (const gchar *folder);
void procmsg_msginfo_write_flags (MsgInfo *msginfo);
-
GHashTable *procmsg_msg_hash_table_create(GSList *mlist)
{
GHashTable *msg_table;
ret = -1;
if (ret < 0)
- g_warning(_("Cache data is corrupted\n"));
+ g_warning("Cache data is corrupted\n");
return ret;
}
#define READ_CACHE_DATA_INT(n, fp) \
{ \
if (fread(&n, sizeof(n), 1, fp) != 1) { \
- g_warning(_("Cache data is corrupted\n")); \
+ g_warning("Cache data is corrupted\n"); \
procmsg_msginfo_free(msginfo); \
break; \
} \
}
cache_file = folder_item_get_cache_file(item);
if ((fp = fopen(cache_file, "rb")) == NULL) {
- debug_print(_("\tNo cache file\n"));
+ debug_print("\tNo cache file\n");
g_free(cache_file);
return NULL;
}
setvbuf(fp, file_buf, _IOFBF, sizeof(file_buf));
g_free(cache_file);
- debug_print(_("\tReading summary cache...\n"));
+ debug_print("\tReading summary cache...\n");
/* compare cache version */
if (fread(&ver, sizeof(ver), 1, fp) != 1 ||
CACHE_VERSION != ver) {
- debug_print(_("Cache version is different. Discarding it.\n"));
+ debug_print("Cache version is different. Discarding it.\n");
fclose(fp);
return NULL;
}
}
fclose(fp);
- debug_print(_("done.\n"));
+ debug_print("done.\n");
return mlist;
}
g_return_if_fail(item != NULL);
g_return_if_fail(item->folder != NULL);
- debug_print(_("\tMarking the messages...\n"));
+ debug_print("\tMarking the messages...\n");
markdir = folder_item_get_path(item);
if (!is_dir_exist(markdir))
item->last_num = lastnum;
- debug_print(_("done.\n"));
+ debug_print("done.\n");
if (newmsg)
- debug_print(_("\t%d new message(s)\n"), newmsg);
+ debug_print("\t%d new message(s)\n", newmsg);
hash_free_value_mem(mark_table);
g_hash_table_destroy(mark_table);
g_return_if_fail(path != NULL);
if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL) {
- g_warning(_("can't open mark file\n"));
+ g_warning("can't open mark file\n");
g_free(path);
return;
}
flags = g_new0(MsgFlags, 1);
flags->perm_flags = perm_flags;
- if(!MSG_IS_REALLY_DELETED(*flags)) {
+ if (!MSG_IS_REALLY_DELETED(*flags)) {
g_hash_table_insert(mark_table, GUINT_TO_POINTER(num), flags);
} else {
g_hash_table_remove(mark_table, GUINT_TO_POINTER(num));
markfile = g_strconcat(folder, G_DIR_SEPARATOR_S, MARK_FILE, NULL);
if ((fp = fopen(markfile, "rb")) == NULL)
- debug_print(_("Mark file not found.\n"));
+ debug_print("Mark file not found.\n");
else if (fread(&ver, sizeof(ver), 1, fp) != 1 || MARK_VERSION != ver) {
- debug_print(_("Mark version is different (%d != %d). "
- "Discarding it.\n"), ver, MARK_VERSION);
+ debug_print("Mark version is different (%d != %d). "
+ "Discarding it.\n", ver, MARK_VERSION);
fclose(fp);
fp = NULL;
}
/* reopen with append mode */
fclose(fp);
if ((fp = fopen(markfile, "ab")) == NULL)
- g_warning(_("Can't open mark file with append mode.\n"));
+ g_warning("Can't open mark file with append mode.\n");
} else {
/* open with overwrite mode if mark file doesn't exist or
version is different */
if ((fp = fopen(markfile, "wb")) == NULL)
- g_warning(_("Can't open mark file with write mode.\n"));
+ g_warning("Can't open mark file with write mode.\n");
else {
ver = MARK_VERSION;
WRITE_CACHE_DATA_INT(ver, fp);
MsgInfo *msginfo = (MsgInfo *)node->data;
procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
+
+ return FALSE;
}
/* return the reversed thread tree */
if (parent == NULL) {
parent = root;
} else {
- if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ if (MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
}
}
g_hash_table_lookup(msgid_table, msgid) == NULL)
g_hash_table_insert(msgid_table, (gchar *)msgid, node);
- subject = msginfo->subject;
- found_subject = subject_table_lookup(subject_table,
- (gchar *) subject);
- if (found_subject == NULL)
- subject_table_insert(subject_table, (gchar *) subject,
- node);
- else {
- /* replace if msg in table is older than current one
- * can add here more stuff. */
- if ( ((MsgInfo*)(found_subject->data))->date_t >
- ((MsgInfo*)(node->data))->date_t ) {
- subject_table_remove(subject_table, (gchar *) subject);
- subject_table_insert(subject_table, (gchar *) subject, node);
- }
+ if (prefs_common.thread_by_subject) {
+ subject = msginfo->subject;
+ found_subject = subject_table_lookup(subject_table,
+ (gchar *) subject);
+ if (found_subject == NULL)
+ subject_table_insert(subject_table, (gchar *) subject,
+ node);
+ else {
+ /* replace if msg in table is older than current one
+ * can add here more stuff. */
+ if ( ((MsgInfo*)(found_subject->data))->date_t >
+ ((MsgInfo*)(node->data))->date_t ) {
+ subject_table_remove(subject_table, (gchar *) subject);
+ subject_table_insert(subject_table, (gchar *) subject, node);
+ }
+ }
}
}
g_node_insert_before
(parent, parent->children, node);
/* CLAWS: ignore thread */
- if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ if (MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, procmsg_ignore_node, NULL);
}
}
* threaded by subject line. we need to handle this in a special way to prevent
* circular reference from a node that has already been threaded by IN-REPLY-TO
* but is also in the subject line hash table */
- for (node = root->children; node != NULL; ) {
- next = node->next;
- msginfo = (MsgInfo *) node->data;
- parent = NULL;
- if (subject_is_reply(msginfo->subject)) {
- parent = subject_table_lookup(subject_table,
- msginfo->subject);
- /* the node may already be threaded by IN-REPLY-TO,
- so go up in the tree to find the parent node */
- if (parent != NULL) {
- if (g_node_is_ancestor(node, parent))
- parent = NULL;
- if (parent == node)
- parent = NULL;
- }
-
- if (parent) {
- g_node_unlink(node);
- g_node_append(parent, node);
- /* CLAWS: ignore thread */
- if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, procmsg_ignore_node, NULL);
+ if (prefs_common.thread_by_subject) {
+ for (node = root->children; node != NULL; ) {
+ next = node->next;
+ msginfo = (MsgInfo *) node->data;
+ parent = NULL;
+ if (subject_is_reply(msginfo->subject)) {
+ parent = subject_table_lookup(subject_table,
+ msginfo->subject);
+ /* the node may already be threaded by IN-REPLY-TO,
+ so go up in the tree to find the parent node */
+ if (parent != NULL) {
+ if (g_node_is_ancestor(node, parent))
+ parent = NULL;
+ if (parent == node)
+ parent = NULL;
}
- }
- }
- node = next;
- }
+ if (parent) {
+ g_node_unlink(node);
+ g_node_append(parent, node);
+ /* CLAWS: ignore thread */
+ if (MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, procmsg_ignore_node, NULL);
+ }
+ }
+ }
+ node = next;
+ }
+ }
+
g_hash_table_destroy(subject_table);
g_hash_table_destroy(msgid_table);
if (!mlist) return;
+ folder_item_update_freeze();
+
for (cur = mlist; cur != NULL; cur = cur->next) {
msginfo = (MsgInfo *)cur->data;
if (!dest) {
dest = msginfo->to_folder;
movelist = g_slist_append(movelist, msginfo);
}
+ procmsg_msginfo_set_to_folder(msginfo, NULL);
}
if (movelist) {
folder_item_move_msgs_with_dest(dest, movelist);
g_slist_free(movelist);
}
+
+ folder_item_update_thaw();
}
void procmsg_copy_messages(GSList *mlist)
if (!mlist) return;
- /*
-
- Horrible: Scanning 2 times for every copy!
-
- hash = procmsg_to_folder_hash_table_create(mlist);
- folder_item_scan_foreach(hash);
- g_hash_table_destroy(hash);
- */
+ folder_item_update_freeze();
for (cur = mlist; cur != NULL; cur = cur->next) {
msginfo = (MsgInfo *)cur->data;
dest = msginfo->to_folder;
copylist = g_slist_append(copylist, msginfo);
}
+ procmsg_msginfo_set_to_folder(msginfo, NULL);
}
if (copylist) {
folder_item_copy_msgs_with_dest(dest, copylist);
g_slist_free(copylist);
}
+
+ folder_item_update_thaw();
}
gchar *procmsg_get_message_file_path(MsgInfo *msginfo)
filename = folder_item_fetch_msg(msginfo->folder, msginfo->msgnum);
if (!filename)
- g_warning(_("can't fetch message %d\n"), msginfo->msgnum);
+ g_warning("can't fetch message %d\n", msginfo->msgnum);
return filename;
}
g_free(file);
- if (MSG_IS_QUEUED(msginfo->flags)) {
+ if (MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags)) {
gchar buf[BUFFSIZE];
while (fgets(buf, sizeof(buf), fp) != NULL)
}
if (MSG_IS_ENCRYPTED(msginfo->flags) &&
- !msginfo->plaintext_file &&
- !msginfo->decryption_failed) {
+ (!msginfo->plaintext_file || msginfo->decryption_failed)) {
rfc2015_decrypt_message(msginfo, mimeinfo_, fp);
if (msginfo->plaintext_file &&
!msginfo->decryption_failed) {
list = folder_item_get_msg_list(queue);
- for(elem = list; elem != NULL; elem = elem->next) {
+ for (elem = list; elem != NULL; elem = elem->next) {
gchar *file;
MsgInfo *msginfo;
file = folder_item_fetch_msg(queue, msginfo->msgnum);
if (file) {
if (procmsg_send_message_queue(file) < 0) {
- g_warning(_("Sending queued message %d failed.\n"), msginfo->msgnum);
+ g_warning("Sending queued message %d failed.\n", msginfo->msgnum);
ret = -1;
} else {
/* CLAWS:
procmsg_msginfo_free(msginfo);
}
- folderview_update_item(queue, FALSE);
-
return ret;
}
+gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
+{
+ FILE *fp, *outfp;
+ gchar buf[BUFFSIZE];
+
+ if ((fp = fopen(in, "rb")) == NULL) {
+ FILE_OP_ERROR(in, "fopen");
+ return -1;
+ }
+ if ((outfp = fopen(out, "wb")) == NULL) {
+ FILE_OP_ERROR(out, "fopen");
+ fclose(fp);
+ return -1;
+ }
+ while (fgets(buf, sizeof(buf), fp) != NULL)
+ if (buf[0] == '\r' || buf[0] == '\n') break;
+ while (fgets(buf, sizeof(buf), fp) != NULL)
+ fputs(buf, outfp);
+ fclose(outfp);
+ fclose(fp);
+ return 0;
+
+}
gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
gboolean is_queued)
{
gint num;
- FILE *fp;
MsgInfo *msginfo;
debug_print("saving sent message...\n");
/* remove queueing headers */
if (is_queued) {
gchar tmp[MAXPATHLEN + 1];
- gchar buf[BUFFSIZE];
- FILE *outfp;
g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.out.%08x",
get_rc_dir(), G_DIR_SEPARATOR, (guint)random());
- if ((fp = fopen(file, "rb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
- return -1;
- }
- if ((outfp = fopen(tmp, "wb")) == NULL) {
- FILE_OP_ERROR(tmp, "fopen");
- fclose(fp);
+
+ if (procmsg_remove_special_headers(file, tmp) !=0)
return -1;
- }
- while (fgets(buf, sizeof(buf), fp) != NULL)
- if (buf[0] == '\r' || buf[0] == '\n') break;
- while (fgets(buf, sizeof(buf), fp) != NULL)
- fputs(buf, outfp);
- fclose(outfp);
- fclose(fp);
folder_item_scan(outbox);
if ((num = folder_item_add_msg(outbox, tmp, TRUE)) < 0) {
}
return -1;
}
- msginfo = folder_item_fetch_msginfo(outbox, num);
- if(msginfo != NULL) {
- procmsg_msginfo_unset_flags(msginfo, ~0, ~0);
+ msginfo = folder_item_get_msginfo(outbox, num);
+ if (msginfo != NULL) {
+ procmsg_msginfo_unset_flags(msginfo, ~0, 0);
procmsg_msginfo_free(msginfo);
}
-
- if(is_queued) {
- unlink(file);
- }
+ folder_item_update(outbox, TRUE);
return 0;
}
g_return_if_fail(msginfo);
if ((tmpfp = procmime_get_first_text_content(msginfo)) == NULL) {
- g_warning(_("Can't get text part\n"));
+ 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);
}
return newmsginfo;
}
+MsgInfo *procmsg_msginfo_get_full_info(MsgInfo *msginfo)
+{
+ MsgInfo *full_msginfo;
+ gchar *file;
+
+ if (msginfo == NULL) return NULL;
+
+ file = procmsg_get_message_file(msginfo);
+ if (!file) {
+ g_warning("procmsg_msginfo_get_full_info(): can't get message file.\n");
+ return NULL;
+ }
+
+ full_msginfo = procheader_parse_file(file, msginfo->flags, TRUE, FALSE);
+ g_free(file);
+ if (!full_msginfo) return NULL;
+
+ full_msginfo->msgnum = msginfo->msgnum;
+ full_msginfo->size = msginfo->size;
+ full_msginfo->mtime = msginfo->mtime;
+ full_msginfo->folder = msginfo->folder;
+#if USE_GPGME
+ full_msginfo->plaintext_file = g_strdup(msginfo->plaintext_file);
+ full_msginfo->decryption_failed = msginfo->decryption_failed;
+#endif
+ procmsg_msginfo_set_to_folder(full_msginfo, msginfo->to_folder);
+
+ return full_msginfo;
+}
+
void procmsg_msginfo_free(MsgInfo *msginfo)
{
if (msginfo == NULL) return;
msginfo->refcnt--;
- if(msginfo->refcnt > 0)
+ if (msginfo->refcnt > 0)
return;
+ debug_print("freeing msginfo %d is %s\n", msginfo->msgnum, msginfo->folder ? msginfo->folder->path : "(nil)");
+
+ if (msginfo->to_folder) {
+ msginfo->to_folder->op_count--;
+ folder_item_update(msginfo->to_folder, F_ITEM_UPDATE_MSGCNT);
+ }
+
g_free(msginfo->fromspace);
g_free(msginfo->references);
g_free(msginfo->returnreceiptto);
guint memusage = 0;
memusage += sizeof(MsgInfo);
- if(msginfo->fromname)
+ if (msginfo->fromname)
memusage += strlen(msginfo->fromname);
- if(msginfo->date)
+ if (msginfo->date)
memusage += strlen(msginfo->date);
- if(msginfo->from)
+ if (msginfo->from)
memusage += strlen(msginfo->from);
- if(msginfo->to)
+ if (msginfo->to)
memusage += strlen(msginfo->to);
- if(msginfo->cc)
+ if (msginfo->cc)
memusage += strlen(msginfo->cc);
- if(msginfo->newsgroups)
+ if (msginfo->newsgroups)
memusage += strlen(msginfo->newsgroups);
- if(msginfo->subject)
+ if (msginfo->subject)
memusage += strlen(msginfo->subject);
- if(msginfo->msgid)
+ if (msginfo->msgid)
memusage += strlen(msginfo->msgid);
- if(msginfo->inreplyto)
+ if (msginfo->inreplyto)
memusage += strlen(msginfo->inreplyto);
- if(msginfo->xface)
+ if (msginfo->xface)
memusage += strlen(msginfo->xface);
- if(msginfo->dispositionnotificationto)
+ if (msginfo->dispositionnotificationto)
memusage += strlen(msginfo->dispositionnotificationto);
- if(msginfo->returnreceiptto)
+ if (msginfo->returnreceiptto)
memusage += strlen(msginfo->returnreceiptto);
- if(msginfo->references)
+ if (msginfo->references)
memusage += strlen(msginfo->references);
- if(msginfo->fromspace)
+ if (msginfo->fromspace)
memusage += strlen(msginfo->fromspace);
return memusage;
Q_NEWS_ACCOUNT_ID = 5,
Q_SAVE_COPY_FOLDER = 6,
Q_REPLY_MESSAGE_ID = 7,
+ Q_FWD_MESSAGE_ID = 8
};
gint procmsg_send_message_queue(const gchar *file)
{"NAID:", NULL, FALSE},
{"SCF:", NULL, FALSE},
{"RMID:", NULL, FALSE},
+ {"FMID:", NULL, FALSE},
{NULL, NULL, FALSE}};
FILE *fp;
gint filepos;
GSList *newsgroup_list = NULL;
gchar *savecopyfolder = NULL;
gchar *replymessageid = NULL;
+ gchar *fwdmessageid = NULL;
gchar buf[BUFFSIZE];
gint hnum;
PrefsAccount *mailac = NULL, *newsac = NULL;
case Q_REPLY_MESSAGE_ID:
if (!replymessageid) replymessageid = g_strdup(p);
break;
+ case Q_FWD_MESSAGE_ID:
+ if (!fwdmessageid) fwdmessageid = g_strdup(p);
+ break;
}
}
filepos = ftell(fp);
- fseek(fp, filepos, SEEK_SET);
if (to_list) {
- debug_print(_("Sending message by mail\n"));
- if(!from) {
- g_warning(_("Queued message header is broken.\n"));
+ debug_print("Sending message by mail\n");
+ if (!from) {
+ g_warning("Queued message header is broken.\n");
mailval = -1;
} else if (mailac && mailac->use_mail_command &&
mailac->mail_command && (* mailac->mail_command)) {
if (!mailac) {
mailac = account_find_from_smtp_server(from, smtpserver);
if (!mailac) {
- g_warning(_("Account not found. "
- "Using current account...\n"));
+ g_warning("Account not found. "
+ "Using current account...\n");
mailac = cur_account;
}
}
else {
PrefsAccount tmp_ac;
- g_warning(_("Account not found.\n"));
+ g_warning("Account not found.\n");
memset(&tmp_ac, 0, sizeof(PrefsAccount));
tmp_ac.address = from;
}
if (mailval < 0) {
if (!local)
- alertpanel_error(
+ alertpanel_error_log(
_("Error occurred while sending the message to `%s'."),
mailac ? mailac->smtp_server : smtpserver);
else
- alertpanel_error(
+ alertpanel_error_log(
_("Error occurred while sending the message with command `%s'."),
(mailac && mailac->use_mail_command &&
mailac->mail_command && (*mailac->mail_command)) ?
}
}
- if(newsgroup_list && (newsval == 0)) {
+ fseek(fp, filepos, SEEK_SET);
+ if (newsgroup_list && (newsval == 0)) {
Folder *folder;
gchar *tmp = NULL;
FILE *tmpfp;
} else {
if (change_file_mode_rw(tmpfp, tmp) < 0) {
FILE_OP_ERROR(tmp, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
while ((newsval == 0) && fgets(buf, sizeof(buf), fp) != NULL) {
}
fclose(tmpfp);
- if(newsval == 0) {
- debug_print(_("Sending message by news\n"));
+ if (newsval == 0) {
+ debug_print("Sending message by news\n");
folder = FOLDER(newsac->folder);
if (mailval == 0 && newsval == 0 && savecopyfolder) {
FolderItem *outbox;
- debug_print(_("saving sent message...\n"));
+ debug_print("saving sent message...\n");
outbox = folder_find_item_from_identifier(savecopyfolder);
- if(!outbox)
+ if (!outbox)
outbox = folder_get_default_outbox();
procmsg_save_to_outbox(outbox, file, TRUE);
}
- if(replymessageid != NULL) {
+ if (replymessageid != NULL || fwdmessageid != NULL) {
gchar **tokens;
FolderItem *item;
- tokens = g_strsplit(replymessageid, "\x7f", 0);
+ if (replymessageid != NULL)
+ tokens = g_strsplit(replymessageid, "\x7f", 0);
+ else
+ tokens = g_strsplit(fwdmessageid, "\x7f", 0);
item = folder_find_item_from_identifier(tokens[0]);
- if(item != NULL) {
+ if (item != NULL) {
MsgInfo *msginfo;
- msginfo = folder_item_fetch_msginfo(item, atoi(tokens[1]));
- if((msginfo != NULL) && (strcmp(msginfo->msgid, tokens[2]) != 0)) {
+ msginfo = folder_item_get_msginfo(item, atoi(tokens[1]));
+ if ((msginfo != NULL) && (strcmp(msginfo->msgid, tokens[2]) != 0)) {
procmsg_msginfo_free(msginfo);
msginfo = NULL;
}
- if(msginfo == NULL) {
- msginfo = folder_item_fetch_msginfo_by_id(item, tokens[2]);
+ if (msginfo == NULL) {
+ msginfo = folder_item_get_msginfo_by_msgid(item, tokens[2]);
}
- if(msginfo != NULL) {
- procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
- procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
-
+ if (msginfo != NULL) {
+ if (replymessageid != NULL) {
+ procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+ procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
+ }
+ else {
+ procmsg_msginfo_unset_flags(msginfo, MSG_REPLIED, 0);
+ procmsg_msginfo_set_flags(msginfo, MSG_FORWARDED, 0);
+ }
procmsg_msginfo_free(msginfo);
}
}
g_free(savecopyfolder);
g_free(replymessageid);
+ g_free(fwdmessageid);
return (newsval != 0 ? newsval : mailval);
}
void procmsg_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
{
- gboolean changed = FALSE;
- FolderItem *item = msginfo->folder;
+ FolderItem *item;
+ MsgInfoUpdate msginfo_update;
- debug_print(_("Setting flags for message %d in folder %s\n"), msginfo->msgnum, item->path);
+ g_return_if_fail(msginfo != NULL);
+ item = msginfo->folder;
+ g_return_if_fail(item != NULL);
+
+ debug_print("Setting flags for message %d in folder %s\n", msginfo->msgnum, item->path);
/* if new flag is set */
- if((perm_flags & MSG_NEW) && !MSG_IS_NEW(msginfo->flags) &&
+ if ((perm_flags & MSG_NEW) && !MSG_IS_NEW(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->new++;
- changed = TRUE;
}
/* if unread flag is set */
- if((perm_flags & MSG_UNREAD) && !MSG_IS_UNREAD(msginfo->flags) &&
+ if ((perm_flags & MSG_UNREAD) && !MSG_IS_UNREAD(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->unread++;
- changed = TRUE;
}
+ if (!MSG_IS_UNREAD(msginfo->flags) &&(perm_flags & MSG_UNREAD)
+ && procmsg_msg_has_marked_parent(msginfo)) {
+ item->unreadmarked++;
+ }
+
+ if (!MSG_IS_MARKED(msginfo->flags) && (perm_flags & MSG_MARKED)) {
+ procmsg_update_unread_children(msginfo, TRUE);
+ }
+
+
/* if ignore thread flag is set */
- if((perm_flags & MSG_IGNORE_THREAD) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- if(MSG_IS_NEW(msginfo->flags) || (perm_flags & MSG_NEW)) {
+ if ((perm_flags & MSG_IGNORE_THREAD) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ if (MSG_IS_NEW(msginfo->flags) || (perm_flags & MSG_NEW)) {
item->new--;
- changed = TRUE;
}
- if(MSG_IS_UNREAD(msginfo->flags) || (perm_flags & MSG_UNREAD)) {
+ if (MSG_IS_UNREAD(msginfo->flags) || (perm_flags & MSG_UNREAD)) {
item->unread--;
- changed = TRUE;
}
+ if ((perm_flags & MSG_UNREAD) || (MSG_IS_UNREAD(msginfo->flags)
+ && procmsg_msg_has_marked_parent(msginfo))) {
+ item->unreadmarked--;
+ }
+ if ((perm_flags & MSG_MARKED) || (MSG_IS_MARKED(msginfo->flags)
+ && !MSG_IS_IGNORE_THREAD(msginfo->flags))) {
+ procmsg_update_unread_children(msginfo, FALSE);
+ }
+
}
- if (MSG_IS_IMAP(msginfo->flags))
+ if (msginfo->folder->folder->type == F_IMAP)
imap_msg_set_perm_flags(msginfo, perm_flags);
msginfo->flags.perm_flags |= perm_flags;
msginfo->flags.tmp_flags |= tmp_flags;
- if(changed) {
- folderview_update_item(item, FALSE);
- }
+ msginfo_update.msginfo = msginfo;
+ hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
+ folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
+
CHANGE_FLAGS(msginfo);
procmsg_msginfo_write_flags(msginfo);
}
void procmsg_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
{
- gboolean changed = FALSE;
- FolderItem *item = msginfo->folder;
+ FolderItem *item;
+ MsgInfoUpdate msginfo_update;
+
+ g_return_if_fail(msginfo != NULL);
+ item = msginfo->folder;
+ g_return_if_fail(item != NULL);
- debug_print(_("Unsetting flags for message %d in folder %s\n"), msginfo->msgnum, item->path);
+ debug_print("Unsetting flags for message %d in folder %s\n", msginfo->msgnum, item->path);
/* if new flag is unset */
- if((perm_flags & MSG_NEW) && MSG_IS_NEW(msginfo->flags) &&
+ if ((perm_flags & MSG_NEW) && MSG_IS_NEW(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->new--;
- changed = TRUE;
}
/* if unread flag is unset */
- if((perm_flags & MSG_UNREAD) && MSG_IS_UNREAD(msginfo->flags) &&
+ if ((perm_flags & MSG_UNREAD) && MSG_IS_UNREAD(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->unread--;
- changed = TRUE;
+ }
+
+ if (MSG_IS_UNREAD(msginfo->flags) && (perm_flags & MSG_UNREAD)
+ && !MSG_IS_IGNORE_THREAD(msginfo->flags)
+ && procmsg_msg_has_marked_parent(msginfo)) {
+ item->unreadmarked--;
+ }
+
+ if (MSG_IS_MARKED(msginfo->flags) && (perm_flags & MSG_MARKED)
+ && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ procmsg_update_unread_children(msginfo, FALSE);
}
/* if ignore thread flag is unset */
- if((perm_flags & MSG_IGNORE_THREAD) && MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- if(MSG_IS_NEW(msginfo->flags) && !(perm_flags & MSG_NEW)) {
+ if ((perm_flags & MSG_IGNORE_THREAD) && MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ if (MSG_IS_NEW(msginfo->flags) && !(perm_flags & MSG_NEW)) {
item->new++;
- changed = TRUE;
}
- if(MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)) {
+ if (MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)) {
item->unread++;
- changed = TRUE;
}
+ if (MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)
+ && procmsg_msg_has_marked_parent(msginfo)) {
+ item->unreadmarked++;
+ }
+ if (MSG_IS_MARKED(msginfo->flags) && !(perm_flags & MSG_MARKED)) {
+ procmsg_update_unread_children(msginfo, TRUE);
+ }
+
}
- if (MSG_IS_IMAP(msginfo->flags))
+ if (msginfo->folder->folder->type == F_IMAP)
imap_msg_unset_perm_flags(msginfo, perm_flags);
msginfo->flags.perm_flags &= ~perm_flags;
msginfo->flags.tmp_flags &= ~tmp_flags;
- if(changed) {
- folderview_update_item(item, FALSE);
- }
+ msginfo_update.msginfo = msginfo;
+ hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
+ folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
+
CHANGE_FLAGS(msginfo);
procmsg_msginfo_write_flags(msginfo);
}
procmsg_write_flags(msginfo, fp);
fclose(fp);
} else {
- g_warning(_("Can't open mark file.\n"));
+ g_warning("Can't open mark file.\n");
}
g_free(destdir);
}
+
+/*!
+ *\brief check for flags (e.g. mark) in prior msgs of current thread
+ *
+ *\param info Current message
+ *\param perm_flags Flags to be checked
+ *\param parentmsgs Hash of prior msgs to avoid loops
+ *
+ *\return gboolean TRUE if perm_flags are found
+ */
+gboolean procmsg_msg_has_flagged_parent_real(MsgInfo *info,
+ MsgPermFlags perm_flags, GHashTable *parentmsgs)
+{
+ MsgInfo *tmp;
+
+ g_return_val_if_fail(info != NULL, FALSE);
+
+ if (info != NULL && info->folder != NULL && info->inreplyto != NULL) {
+ tmp = folder_item_get_msginfo_by_msgid(info->folder,
+ info->inreplyto);
+ if (tmp && (tmp->flags.perm_flags & perm_flags)) {
+ procmsg_msginfo_free(tmp);
+ return TRUE;
+ } else if (tmp != NULL) {
+ gboolean result;
+
+ if (g_hash_table_lookup(parentmsgs, info)) {
+ debug_print("loop detected: %s%c%d\n",
+ folder_item_get_path(info->folder),
+ G_DIR_SEPARATOR, info->msgnum);
+ result = FALSE;
+ } else {
+ g_hash_table_insert(parentmsgs, info, "1");
+ result = procmsg_msg_has_flagged_parent_real(
+ tmp, perm_flags, parentmsgs);
+ }
+ procmsg_msginfo_free(tmp);
+ return result;
+ } else {
+ return FALSE;
+ }
+ } else
+ return FALSE;
+}
+
+/*!
+ *\brief Callback for cleaning up hash of parentmsgs
+ */
+gboolean parentmsgs_hash_remove(gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ return TRUE;
+}
+
+/*!
+ *\brief Set up list of parentmsgs
+ * See procmsg_msg_has_flagged_parent_real()
+ */
+gboolean procmsg_msg_has_flagged_parent(MsgInfo *info, MsgPermFlags perm_flags)
+{
+ gboolean result;
+ GHashTable *parentmsgs = g_hash_table_new(NULL, NULL);
+
+ result = procmsg_msg_has_flagged_parent_real(info, perm_flags, parentmsgs);
+ g_hash_table_foreach_remove(parentmsgs, parentmsgs_hash_remove, NULL);
+ g_hash_table_destroy(parentmsgs);
+ return result;
+}
+
+/*!
+ *\brief Check if msgs prior in thread are marked
+ * See procmsg_msg_has_flagged_parent_real()
+ */
+gboolean procmsg_msg_has_marked_parent(MsgInfo *info)
+{
+ return procmsg_msg_has_flagged_parent(info, MSG_MARKED);
+}
+
+
+GSList *procmsg_find_children_func(MsgInfo *info,
+ GSList *children, GSList *all)
+{
+ GSList *cur;
+
+ g_return_val_if_fail(info!=NULL, children);
+ if (info->msgid == NULL)
+ return children;
+
+ for (cur = all; cur != NULL; cur = g_slist_next(cur)) {
+ MsgInfo *tmp = (MsgInfo *)cur->data;
+ if (tmp->inreplyto && !strcmp(tmp->inreplyto, info->msgid)) {
+ /* Check if message is already in the list */
+ if ((children == NULL) ||
+ (g_slist_index(children, tmp) == -1)) {
+ children = g_slist_prepend(children,
+ procmsg_msginfo_new_ref(tmp));
+ children = procmsg_find_children_func(tmp,
+ children,
+ all);
+ }
+ }
+ }
+ return children;
+}
+
+GSList *procmsg_find_children (MsgInfo *info)
+{
+ GSList *children;
+ GSList *all, *cur;
+
+ g_return_val_if_fail(info!=NULL, NULL);
+ all = folder_item_get_msg_list(info->folder);
+ children = procmsg_find_children_func(info, NULL, all);
+ if (children != NULL) {
+ for (cur = all; cur != NULL; cur = g_slist_next(cur)) {
+ /* this will not free the used pointers
+ created with procmsg_msginfo_new_ref */
+ procmsg_msginfo_free((MsgInfo *)cur->data);
+ }
+ }
+ g_slist_free(all);
+
+ return children;
+}
+
+void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
+{
+ GSList *children = procmsg_find_children(info);
+ GSList *cur;
+ for (cur = children; cur != NULL; cur = g_slist_next(cur)) {
+ MsgInfo *tmp = (MsgInfo *)cur->data;
+ if(MSG_IS_UNREAD(tmp->flags) && !MSG_IS_IGNORE_THREAD(tmp->flags)) {
+ if(newly_marked)
+ info->folder->unreadmarked++;
+ else
+ info->folder->unreadmarked--;
+ folder_item_update(info->folder, F_ITEM_UPDATE_MSGCNT);
+ }
+ procmsg_msginfo_free(tmp);
+ }
+ g_slist_free(children);
+}
+
+/**
+ * Set the destination folder for a copy or move operation
+ *
+ * \param msginfo The message which's destination folder is changed
+ * \param to_folder The destination folder for the operation
+ */
+void procmsg_msginfo_set_to_folder(MsgInfo *msginfo, FolderItem *to_folder)
+{
+ if(msginfo->to_folder != NULL) {
+ msginfo->to_folder->op_count--;
+ folder_item_update(msginfo->to_folder, F_ITEM_UPDATE_MSGCNT);
+ }
+ msginfo->to_folder = to_folder;
+ if(to_folder != NULL) {
+ to_folder->op_count++;
+ folder_item_update(msginfo->to_folder, F_ITEM_UPDATE_MSGCNT);
+ }
+}