aboutsummaryrefslogtreecommitdiff
path: root/src/procmsg.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-06-07 08:52:01 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-06-07 08:52:01 +0000
commitbfed07b21a7b4f1b7b5eebd99e469a717a81be26 (patch)
tree9b30bc8bb89cd22261d6285db70d8669b8a4fc64 /src/procmsg.c
parent7f0a8d80fdb7ad6a254bbfa5eb8af0f21f206067 (diff)
added an option to apply filter rules to sent messages.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@317 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/procmsg.c')
-rw-r--r--src/procmsg.c113
1 files changed, 51 insertions, 62 deletions
diff --git a/src/procmsg.c b/src/procmsg.c
index c97d7b02..b852b3ce 100644
--- a/src/procmsg.c
+++ b/src/procmsg.c
@@ -33,6 +33,7 @@
#include "send_message.h"
#include "procmime.h"
#include "statusbar.h"
+#include "prefs_common.h"
#include "prefs_filter.h"
#include "filter.h"
#include "folder.h"
@@ -1223,7 +1224,8 @@ void procmsg_empty_all_trash(void)
}
}
-gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
+gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs,
+ gboolean filter_msgs)
{
gint ret = 0;
GSList *mlist = NULL;
@@ -1239,45 +1241,65 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs)
for (cur = mlist; cur != NULL; cur = cur->next) {
gchar *file;
MsgInfo *msginfo = (MsgInfo *)cur->data;
+ QueueInfo *qinfo;
+ gchar tmp[MAXPATHLEN + 1];
file = procmsg_get_message_file(msginfo);
- if (file) {
- QueueInfo *qinfo;
-
- qinfo = send_get_queue_info(file);
- if (!qinfo || send_message_queue(qinfo) < 0) {
- g_warning(_("Sending queued message %d failed.\n"),
- msginfo->msgnum);
- } else {
- ret++;
- if (save_msgs) {
- FolderItem *outbox;
- outbox = account_get_special_folder
- (qinfo->ac, F_OUTBOX);
- procmsg_save_to_outbox(outbox, file,
- TRUE);
- }
- folder_item_remove_msg(queue, msginfo);
- }
+ if (!file)
+ continue;
+
+ qinfo = send_get_queue_info(file);
+ if (!qinfo || send_message_queue(qinfo) < 0) {
+ g_warning("Sending queued message %d failed.\n",
+ msginfo->msgnum);
send_queue_info_free(qinfo);
g_free(file);
+ continue;
}
- procmsg_msginfo_free(msginfo);
- }
+ g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.out.%08x",
+ get_rc_dir(), G_DIR_SEPARATOR,
+ (guint)random());
+
+ if (send_get_queue_contents(qinfo, tmp) == 0) {
+ if (save_msgs) {
+ FolderItem *outbox;
+ outbox = account_get_special_folder
+ (qinfo->ac, F_OUTBOX);
+ procmsg_save_to_outbox(outbox, tmp);
+ }
+ if (filter_msgs) {
+ FilterInfo *fltinfo;
- g_slist_free(mlist);
+ fltinfo = filter_info_new();
+ fltinfo->account = qinfo->ac;
+ fltinfo->flags.perm_flags = 0;
+ fltinfo->flags.tmp_flags = MSG_RECEIVED;
+
+ filter_apply(prefs_common.fltlist, tmp,
+ fltinfo);
+
+ filter_info_free(fltinfo);
+ }
+ unlink(tmp);
+ }
+
+ folder_item_remove_msg(queue, msginfo);
+ ret++;
+
+ send_queue_info_free(qinfo);
+ g_free(file);
+ }
+ procmsg_msg_list_free(mlist);
queue->mtime = 0;
return ret;
}
-gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
- gboolean is_queued)
+gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file)
{
gint num;
- FILE *fp;
MsgFlags flag = {0, 0};
debug_print("saving sent message...\n");
@@ -1286,43 +1308,10 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
outbox = folder_get_default_outbox();
g_return_val_if_fail(outbox != NULL, -1);
- /* 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);
- 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, &flag, TRUE)) < 0) {
- g_warning("can't save message\n");
- unlink(tmp);
- return -1;
- }
- } else {
- folder_item_scan(outbox);
- if ((num = folder_item_add_msg
- (outbox, file, &flag, FALSE)) < 0) {
- g_warning("can't save message\n");
- return -1;
- }
+ folder_item_scan(outbox);
+ if ((num = folder_item_add_msg(outbox, file, &flag, FALSE)) < 0) {
+ g_warning("can't save message\n");
+ return -1;
}
return 0;