+ }
+
+ while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, qentry))
+ != -1) {
+ gchar *p = buf + strlen(qentry[hnum].name);
+
+ switch (hnum) {
+ case Q_SENDER:
+ if (!from) from = g_strdup(p);
+ break;
+ case Q_SMTPSERVER:
+ if (!smtpserver) smtpserver = g_strdup(p);
+ break;
+ case Q_RECIPIENTS:
+ to_list = address_list_append(to_list, p);
+ break;
+ case Q_NEWSGROUPS:
+ newsgroup_list = newsgroup_list_append(newsgroup_list, p);
+ break;
+ case Q_MAIL_ACCOUNT_ID:
+ mailac = account_find_from_id(atoi(p));
+ break;
+ case Q_NEWS_ACCOUNT_ID:
+ newsac = account_find_from_id(atoi(p));
+ break;
+ case Q_SAVE_COPY_FOLDER:
+ if (!savecopyfolder) savecopyfolder = g_strdup(p);
+ break;
+ case Q_REPLY_MESSAGE_ID:
+ if (!replymessageid) replymessageid = 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"));
+ mailval = -1;
+ } else if (mailac && mailac->use_mail_command &&
+ mailac->mail_command && (* mailac->mail_command)) {
+ mailval = send_message_local(mailac->mail_command, fp);
+ local = 1;
+ } else if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
+ mailval = send_message_local(prefs_common.extsend_cmd, fp);
+ local = 1;
+ } else {
+ if (!mailac) {
+ mailac = account_find_from_smtp_server(from, smtpserver);
+ if (!mailac) {
+ g_warning(_("Account not found. "
+ "Using current account...\n"));
+ mailac = cur_account;
+ }
+ }
+
+ if (mailac)
+ mailval = send_message_smtp(mailac, to_list, fp);
+ else {
+ PrefsAccount tmp_ac;
+
+ g_warning(_("Account not found.\n"));
+
+ memset(&tmp_ac, 0, sizeof(PrefsAccount));
+ tmp_ac.address = from;
+ tmp_ac.smtp_server = smtpserver;
+ tmp_ac.smtpport = SMTP_PORT;
+ mailval = send_message_smtp(&tmp_ac, to_list, fp);
+ }
+ }
+ if (mailval < 0) {
+ if (!local)
+ alertpanel_error(
+ _("Error occurred while sending the message to `%s'."),
+ mailac ? mailac->smtp_server : smtpserver);
+ else
+ alertpanel_error(
+ _("Error occurred while sending the message with command `%s'."),
+ (mailac && mailac->use_mail_command &&
+ mailac->mail_command && (*mailac->mail_command)) ?
+ mailac->mail_command : prefs_common.extsend_cmd);
+ }
+ }
+
+ if(newsgroup_list && (newsval == 0)) {
+ Folder *folder;
+ gchar *tmp = NULL;
+ FILE *tmpfp;
+
+ /* write to temporary file */
+ tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
+ G_DIR_SEPARATOR, (gint)file);
+ if ((tmpfp = fopen(tmp, "wb")) == NULL) {
+ FILE_OP_ERROR(tmp, "fopen");
+ newsval = -1;
+ alertpanel_error(_("Could not create temporary file for news sending."));
+ } else {
+ if (change_file_mode_rw(tmpfp, tmp) < 0) {
+ FILE_OP_ERROR(tmp, "chmod");
+ g_warning(_("can't change file mode\n"));
+ }
+
+ while ((newsval == 0) && fgets(buf, sizeof(buf), fp) != NULL) {
+ if (fputs(buf, tmpfp) == EOF) {
+ FILE_OP_ERROR(tmp, "fputs");
+ newsval = -1;
+ alertpanel_error(_("Error when writing temporary file for news sending."));
+ }
+ }
+ fclose(tmpfp);
+
+ if(newsval == 0) {
+ debug_print(_("Sending message by news\n"));
+
+ folder = FOLDER(newsac->folder);
+
+ newsval = news_post(folder, tmp);
+ if (newsval < 0) {
+ alertpanel_error(_("Error occurred while posting the message to %s ."),
+ newsac->nntp_server);
+ }
+ }
+ unlink(tmp);
+ }
+ g_free(tmp);
+ }
+
+ slist_free_strings(to_list);
+ g_slist_free(to_list);
+ slist_free_strings(newsgroup_list);
+ g_slist_free(newsgroup_list);
+ g_free(from);
+ g_free(smtpserver);
+ fclose(fp);
+
+ /* save message to outbox */
+ if (mailval == 0 && newsval == 0 && savecopyfolder) {
+ FolderItem *outbox;
+
+ debug_print(_("saving sent message...\n"));
+
+ outbox = folder_find_item_from_identifier(savecopyfolder);
+ if(!outbox)
+ outbox = folder_get_default_outbox();
+
+ procmsg_save_to_outbox(outbox, file, TRUE);
+ }
+
+ if(replymessageid != NULL) {
+ gchar **tokens;
+ FolderItem *item;
+
+ tokens = g_strsplit(replymessageid, "\x7f", 0);
+ item = folder_find_item_from_identifier(tokens[0]);
+ if(item != NULL) {
+ MsgInfo *msginfo;
+
+ msginfo = folder_item_fetch_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) {
+ procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+ procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
+
+ procmsg_msginfo_free(msginfo);
+ }
+ }
+ g_strfreev(tokens);
+ }
+
+ g_free(savecopyfolder);
+ g_free(replymessageid);
+
+ return (newsval != 0 ? newsval : mailval);
+}
+
+#define CHANGE_FLAGS(msginfo) \
+{ \
+if (msginfo->folder->folder->change_flags != NULL) \
+msginfo->folder->folder->change_flags(msginfo->folder->folder, \
+ msginfo->folder, \
+ msginfo); \
+}
+
+void procmsg_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
+{
+ gboolean changed = FALSE;
+ FolderItem *item = msginfo->folder;
+
+ debug_print(_("Setting flags for message %d in folder %s\n"), msginfo->msgnum, item->path);