/*
* 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; \
} \
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;
}
/* 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);
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;
}
}
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) {
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);
}
- folder_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);
+ msginfo = folder_item_get_msginfo(outbox, num);
if (msginfo != NULL) {
procmsg_msginfo_unset_flags(msginfo, ~0, 0);
procmsg_msginfo_free(msginfo);
}
+ 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);
}
full_msginfo->size = msginfo->size;
full_msginfo->mtime = msginfo->mtime;
full_msginfo->folder = msginfo->folder;
- full_msginfo->to_folder = msginfo->to_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;
}
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);
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);
if (to_list) {
debug_print("Sending message by mail\n");
if (!from) {
- g_warning(_("Queued message header is broken.\n"));
+ 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)) ?
} 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) {
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) {
MsgInfo *msginfo;
- msginfo = folder_item_fetch_msginfo(item, atoi(tokens[1]));
+ 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]);
+ 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 (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)
{
- 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("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) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->new++;
- item->need_update = TRUE;
}
/* if unread flag is set */
if ((perm_flags & MSG_UNREAD) && !MSG_IS_UNREAD(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->unread++;
- item->need_update = 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)) {
item->new--;
- item->need_update = TRUE;
}
if (MSG_IS_UNREAD(msginfo->flags) || (perm_flags & MSG_UNREAD)) {
item->unread--;
- item->need_update = 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))
msginfo->flags.perm_flags |= perm_flags;
msginfo->flags.tmp_flags |= tmp_flags;
+ 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)
{
- 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);
if ((perm_flags & MSG_NEW) && MSG_IS_NEW(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->new--;
- item->need_update = TRUE;
}
/* if unread flag is unset */
if ((perm_flags & MSG_UNREAD) && MSG_IS_UNREAD(msginfo->flags) &&
!MSG_IS_IGNORE_THREAD(msginfo->flags)) {
item->unread--;
- item->need_update = 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)) {
item->new++;
- item->need_update = TRUE;
}
if (MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)) {
item->unread++;
- item->need_update = 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))
msginfo->flags.perm_flags &= ~perm_flags;
msginfo->flags.tmp_flags &= ~tmp_flags;
+ 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);
+ }
+}