[balsa/69-resend-message] Various: Refactor resending a message
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/69-resend-message] Various: Refactor resending a message
- Date: Tue, 1 Mar 2022 19:34:23 +0000 (UTC)
commit d4de479bef5a77cd2d882e9314b306998cd7a80b
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Tue Mar 1 14:29:33 2022 -0500
Various: Refactor resending a message
Move the GMimeMessage manipulation from src/sendmsg-window.c to libbalsa/send.c;
see https://gitlab.gnome.org/GNOME/balsa/-/issues/69#note_1396270 and replies.
Also fix saving and continuing a resend message.
modified: libbalsa/send.c
modified: src/balsa-index.c
modified: src/message-window.c
modified: src/sendmsg-window.c
modified: src/sendmsg-window.h
libbalsa/send.c | 170 +++++++++++++++----
src/balsa-index.c | 2 +-
src/message-window.c | 4 +-
src/sendmsg-window.c | 470 +++++++++++++++++++++++----------------------------
src/sendmsg-window.h | 4 +-
5 files changed, 353 insertions(+), 297 deletions(-)
---
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 82bf814f8..3376dcc93 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -228,6 +228,7 @@ static LibBalsaMsgCreateResult create_mime_message(LibBalsaMessage *message,
GMimeMessage **return_message,
GError **error);
static LibBalsaMsgCreateResult libbalsa_create_msg(LibBalsaMessage *message,
+ gboolean resending,
gboolean flow,
GError **error);
static LibBalsaMsgCreateResult libbalsa_fill_msg_queue_item_from_queu(LibBalsaMessage *message,
@@ -392,7 +393,7 @@ dump_queue(const char *msg)
/* libbalsa_message_queue:
places given message in the outbox.
*/
-static void libbalsa_set_message_id(GMimeMessage *mime_message);
+static void libbalsa_set_message_id(GMimeMessage *mime_message, gboolean resending);
static LibBalsaMsgCreateResult
lbs_message_queue_real(LibBalsaMessage *message,
@@ -405,12 +406,15 @@ lbs_message_queue_real(LibBalsaMessage *message,
LibBalsaMsgCreateResult result;
GMimeMessage *mime_msg;
guint big_message;
+ gboolean resending;
gboolean rc;
g_assert(error != NULL);
g_return_val_if_fail(message, LIBBALSA_MESSAGE_CREATE_ERROR);
- if ((result = libbalsa_create_msg(message, flow, error)) !=
+ resending = libbalsa_message_get_user_header(message, "X-Balsa-Resend") != NULL;
+
+ if ((result = libbalsa_create_msg(message, resending, flow, error)) !=
LIBBALSA_MESSAGE_CREATE_OK) {
return result;
}
@@ -445,7 +449,7 @@ lbs_message_queue_real(LibBalsaMessage *message,
g_mime_part_set_content_encoding(GMIME_PART
(mime_msgs[i]->mime_part),
GMIME_CONTENT_ENCODING_7BIT);
- libbalsa_set_message_id(mime_msgs[i]);
+ libbalsa_set_message_id(mime_msgs[i], resending);
}
if (rc) {
/* Temporarily modify message by changing its mime_msg: */
@@ -1216,6 +1220,44 @@ get_mailbox_names(GList *list,
return list;
}
+static LibBalsaMsgCreateResult
+lbs_parse_message_body(LibBalsaMessageBody *body,
+ GMimeMessage **return_message,
+ GError **error)
+{
+ GMimeStream *stream;
+ GError *err = NULL;
+ GMimeParser *parser;
+ GMimeMessage *mime_message;
+
+ stream = libbalsa_vfs_create_stream(body->file_uri, 0, FALSE, &err);
+
+ if (stream == NULL) {
+ if (err != NULL) {
+ const char *uri = libbalsa_vfs_get_uri_utf8(body->file_uri);
+ gchar *msg = err->message != NULL ?
+ g_strdup_printf(_("Cannot read %s: %s"), uri, err->message) :
+ g_strdup_printf(_("Cannot read %s"), uri);
+ g_set_error(error, err->domain, err->code, "%s", msg);
+ g_clear_error(&err);
+ g_free(msg);
+ }
+
+ return LIBBALSA_MESSAGE_CREATE_ERROR;
+ }
+
+ parser = g_mime_parser_new_with_stream(stream);
+ g_mime_parser_set_format(parser, GMIME_FORMAT_MESSAGE);
+ g_object_unref(stream);
+
+ mime_message = g_mime_parser_construct_message(parser, libbalsa_parser_options());
+ g_object_unref(parser);
+
+ *return_message = mime_message; /* Steal the reference */
+
+ return LIBBALSA_MESSAGE_CREATE_OK;
+}
+
static inline gboolean
ia_list_not_empty(InternetAddressList *ial)
{
@@ -1293,33 +1335,25 @@ create_mime_message(LibBalsaMessage *message,
lbs_set_content(GMIME_PART(mime_part),
"Note: this is _not_ the real body!\n");
} else if (g_ascii_strcasecmp(mime_type[0], "message") == 0) {
- GMimeStream *stream;
- GMimeParser *parser;
+ LibBalsaMsgCreateResult res;
GMimeMessage *mime_msg;
- GError *err = NULL;
- stream = libbalsa_vfs_create_stream(body->file_uri, 0, FALSE, &err);
- if (!stream) {
- if (err != NULL) {
- gchar *msg =
- err->message
- ? g_strdup_printf(_("Cannot read %s: %s"),
- libbalsa_vfs_get_uri_utf8(body->file_uri),
- err->message)
- : g_strdup_printf(_("Cannot read %s"),
- libbalsa_vfs_get_uri_utf8(body->file_uri));
- g_set_error(error, err->domain, err->code, "%s", msg);
- g_clear_error(&err);
- g_free(msg);
- }
+ res = lbs_parse_message_body(body, &mime_msg, error);
+ if (res != LIBBALSA_MESSAGE_CREATE_OK) {
g_strfreev(mime_type);
- return LIBBALSA_MESSAGE_CREATE_ERROR;
+ return res;
}
- parser = g_mime_parser_new_with_stream(stream);
- g_mime_parser_set_format(parser, GMIME_FORMAT_MESSAGE);
- g_object_unref(stream);
- mime_msg = g_mime_parser_construct_message(parser, libbalsa_parser_options());
- g_object_unref(parser);
+
+ if (libbalsa_message_get_user_header(message, "X-Balsa-Resend") != NULL) {
+ /* This attachment is a message being resent;
+ * We are saving the message to the draft box,
+ * and it currently has no subject;
+ * to be helpful, copy the subject of the message being resent,
+ * so the message index in the draft box shows what is happening;
+ * the subject we set here is ignored when the message is sent. */
+ libbalsa_message_set_subject(message, g_mime_message_get_subject(mime_msg));
+ }
+
mime_part =
GMIME_OBJECT(g_mime_message_part_new_with_message
(mime_type[1], mime_msg));
@@ -1612,7 +1646,7 @@ base32_char(guint8 val)
/* Create a message-id and set it on the mime message.
*/
static void
-libbalsa_set_message_id(GMimeMessage *mime_message)
+libbalsa_set_message_id(GMimeMessage *mime_message, gboolean resending)
{
static GMutex mutex; /* as to make me thread-safe... */
static GRand *rand = NULL;
@@ -1628,7 +1662,6 @@ libbalsa_set_message_id(GMimeMessage *mime_message)
gchar *message_id;
guint8 *src;
gchar *dst;
- gboolean is_resend;
g_mutex_lock(&mutex);
if (rand == NULL) {
@@ -1678,8 +1711,7 @@ libbalsa_set_message_id(GMimeMessage *mime_message)
}
}
- is_resend = g_mime_object_get_header(GMIME_OBJECT(mime_message), "Resent-From") != NULL;
- if (is_resend) {
+ if (resending) {
g_mime_object_prepend_header(GMIME_OBJECT(mime_message),
"Resent-Message-ID",
message_id,
@@ -1691,12 +1723,86 @@ libbalsa_set_message_id(GMimeMessage *mime_message)
g_free(message_id);
}
+static void
+lbs_prepend_resent_header(GMimeObject *object,
+ InternetAddressList *list,
+ const char *field)
+{
+ if (ia_list_not_empty(list)) {
+ char *value = internet_address_list_to_string(list, NULL, FALSE);
+ g_mime_object_prepend_header(object, field, value, NULL);
+ g_free(value);
+ }
+}
+
+static void
+lbs_add_resent_headers(LibBalsaMessage *message, GMimeMessage *mime_message)
+{
+ LibBalsaMessageHeaders *headers = libbalsa_message_get_headers(message);
+ GMimeObject *object = GMIME_OBJECT(mime_message);
+ const char *mailbox = "";
+ char *value;
+ GDateTime *date_time;
+
+ if (ia_list_not_empty(headers->from)) {
+ InternetAddress *ia = internet_address_list_get_address(headers->from, 0);
+ while (ia != NULL && INTERNET_ADDRESS_IS_GROUP(ia))
+ ia = internet_address_list_get_address(INTERNET_ADDRESS_GROUP( ia)->members, 0);
+ if (ia != NULL)
+ mailbox = INTERNET_ADDRESS_MAILBOX(ia)->addr;
+ }
+ g_mime_object_prepend_header(object, "Resent-From", mailbox, NULL);
+
+ lbs_prepend_resent_header(object, headers->to_list, "Resent-To");
+ lbs_prepend_resent_header(object, headers->cc_list, "Resent-CC");
+ lbs_prepend_resent_header(object, headers->bcc_list, "Resent-BCC");
+
+ date_time = g_date_time_new_from_unix_local(headers->date);
+ value = g_mime_utils_header_format_date(date_time);
+ g_date_time_unref(date_time);
+ g_mime_object_prepend_header(object, "Resent-Date", value, NULL);
+ g_free(value);
+}
+
+static LibBalsaMsgCreateResult
+create_mime_message_resend(LibBalsaMessage *message,
+ GMimeMessage **return_message,
+ GError **error)
+{
+ LibBalsaMessageBody *body;
+ LibBalsaMsgCreateResult res;
+ GMimeMessage *mime_message;
+
+ body = libbalsa_message_get_body_list(message);
+
+ g_assert(body != NULL);
+ g_assert(body->content_type != NULL);
+ g_assert(strcasecmp(body->content_type, "message/rfc822") == 0);
+ g_assert(body->parts == NULL);
+ g_assert(body->next == NULL);
+
+ res = lbs_parse_message_body(body, &mime_message, error);
+ if (res == LIBBALSA_MESSAGE_CREATE_OK) {
+ lbs_add_resent_headers(message, mime_message);
+ libbalsa_message_set_subject(message, g_mime_message_get_subject(mime_message));
+
+ libbalsa_message_set_mime_message(message, mime_message);
+ /* message now holds a reference to mime_message, so we do not add one here: */
+ if (return_message != NULL)
+ *return_message = mime_message;
+
+ g_object_unref(mime_message);
+ }
+
+ return res;
+}
/* balsa_create_msg:
copies message to msg.
*/
static LibBalsaMsgCreateResult
libbalsa_create_msg(LibBalsaMessage *message,
+ gboolean resending,
gboolean flow,
GError **error)
{
@@ -1705,12 +1811,14 @@ libbalsa_create_msg(LibBalsaMessage *message,
mime_message = libbalsa_message_get_mime_message(message);
if (mime_message == NULL) {
LibBalsaMsgCreateResult res =
+ resending ?
+ create_mime_message_resend(message, &mime_message, error) :
create_mime_message(message, flow, FALSE, &mime_message, error);
if (res != LIBBALSA_MESSAGE_CREATE_OK)
return res;
}
- libbalsa_set_message_id(mime_message);
+ libbalsa_set_message_id(mime_message, resending);
return LIBBALSA_MESSAGE_CREATE_OK;
}
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 7297d9a21..3fe4b3b5a 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -1690,7 +1690,7 @@ bndx_compose_foreach(BalsaIndex * index, SendType send_type)
sm = sendmsg_window_reply(mailbox, msgno, send_type);
break;
case SEND_RESEND:
- sm = sendmsg_window_resend(mailbox, msgno);
+ sm = sendmsg_window_forward(mailbox, msgno, send_type);
break;
case SEND_CONTINUE:
sm = sendmsg_window_continue(mailbox, msgno);
diff --git a/src/message-window.c b/src/message-window.c
index 933774c3c..e624fbd0f 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -449,7 +449,7 @@ mw_forward_attached_activated(GSimpleAction * action, GVariant * parameter,
sendmsg_window_forward(libbalsa_message_get_mailbox(mw->message),
libbalsa_message_get_msgno(mw->message),
- TRUE);
+ SEND_FORWARD_ATTACH);
}
static void
@@ -462,7 +462,7 @@ mw_forward_inline_activated(GSimpleAction * action, GVariant * parameter,
sendmsg_window_forward(libbalsa_message_get_mailbox(mw->message),
libbalsa_message_get_msgno(mw->message),
- FALSE);
+ SEND_FORWARD_INLINE);
}
#if 0
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index e243b104a..b456259cc 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2973,7 +2973,9 @@ continue_body(BalsaSendmsg * bsmsg, LibBalsaMessage * message)
/* if the first part is of type text/plain with a NULL filename, it
was the message... */
- if (body != NULL && body->filename == NULL) {
+ if (body != NULL &&
+ body->filename == NULL &&
+ libbalsa_message_body_type(body) == LIBBALSA_MESSAGE_BODY_TYPE_TEXT) {
GString *rbdy;
gchar *body_type = libbalsa_message_body_get_mime_type(body);
gint llen = -1;
@@ -4926,86 +4928,34 @@ sw_required_charset(BalsaSendmsg * bsmsg, const gchar * text)
return charset;
}
-static void
-bsmsg_add_resent_header(BalsaSendmsg *bsmsg,
- GMimeObject *mime_object,
- const char *address_view_type,
- const char *field)
-{
- InternetAddressList *list;
- char *value;
-
- list = libbalsa_address_view_get_list(bsmsg->recipient_view, address_view_type);
- value = internet_address_list_to_string(list, NULL, FALSE);
- g_mime_object_prepend_header(mime_object, field, value, NULL);
- g_free(value);
-}
-
-static LibBalsaMessage *
-bsmsg2resent_message(BalsaSendmsg *bsmsg)
-{
- LibBalsaMessage *message;
- GMimeMessage *mime_message;
- GMimeObject *mime_object;
- InternetAddress *ia;
- char *value;
- GDateTime *date_time;
-
- message = libbalsa_message_new();
-
- mime_message = libbalsa_message_get_mime_message(bsmsg->parent_message);
- libbalsa_message_set_mime_message(message, g_object_ref(mime_message));
-
- mime_object = GMIME_OBJECT(mime_message);
-
- ia = libbalsa_identity_get_address(bsmsg->ident);
- value = internet_address_to_string(ia, NULL, FALSE);
- g_mime_object_prepend_header(mime_object, "Resent-From", value, NULL);
- g_free(value);
-
- bsmsg_add_resent_header(bsmsg, mime_object, "To:", "Resent-To");
- bsmsg_add_resent_header(bsmsg, mime_object, "CC:", "Resent-Cc");
- bsmsg_add_resent_header(bsmsg, mime_object, "BCC:", "Resent-Bcc");
-
- /* get the fcc-box from the option menu widget */
- bsmsg->fcc_url =
- g_strdup(balsa_mblist_mru_option_menu_get(bsmsg->fcc[1]));
-
- date_time = g_date_time_new_now_local();
- value = g_mime_utils_header_format_date(date_time);
- g_date_time_unref(date_time);
- g_mime_object_prepend_header(mime_object, "Resent-Date", value, NULL);
- g_free(value);
-
- return message;
-}
-
static LibBalsaMessage *
bsmsg2message(BalsaSendmsg * bsmsg)
{
LibBalsaMessage *message;
LibBalsaMessageHeaders *headers;
LibBalsaMessageBody *body;
- gchar *tmp;
GtkTextIter start, end;
LibBalsaIdentity *ident = bsmsg->ident;
InternetAddress *ia = libbalsa_identity_get_address(ident);
GtkTextBuffer *buffer;
GtkTextBuffer *new_buffer = NULL;
+ message = libbalsa_message_new();
+
if (bsmsg->type == SEND_RESEND)
- return bsmsg2resent_message(bsmsg);
+ libbalsa_message_set_user_header(message, "X-Balsa-Resend", "message is to be resent");
- message = libbalsa_message_new();
headers = libbalsa_message_get_headers(message);
headers->from = internet_address_list_new ();
internet_address_list_add(headers->from, ia);
- tmp = gtk_editable_get_chars(GTK_EDITABLE(bsmsg->subject[1]), 0, -1);
- strip_chars(tmp, "\r\n");
- libbalsa_message_set_subject(message, tmp);
- g_free(tmp);
+ if (bsmsg->subject[1] != NULL) {
+ char *subject = gtk_editable_get_chars(GTK_EDITABLE(bsmsg->subject[1]), 0, -1);
+ strip_chars(subject, "\r\n");
+ libbalsa_message_set_subject(message, subject);
+ g_free(subject);
+ }
headers->to_list =
libbalsa_address_view_get_list(bsmsg->recipient_view, "To:");
@@ -5021,92 +4971,97 @@ bsmsg2message(BalsaSendmsg * bsmsg)
bsmsg->fcc_url =
g_strdup(balsa_mblist_mru_option_menu_get(bsmsg->fcc[1]));
- headers->reply_to =
- libbalsa_address_view_get_list(bsmsg->replyto_view, "Reply To:");
-
- if (bsmsg->req_mdn)
- libbalsa_message_set_dispnotify(message, ia);
libbalsa_message_set_request_dsn(message, bsmsg->req_dsn);
+ if (bsmsg->type != SEND_RESEND) {
+ headers->reply_to = libbalsa_address_view_get_list(bsmsg->replyto_view, "Reply To:");
- sw_set_header_from_path(message, "Face", libbalsa_identity_get_face_path(ident),
- /* Translators: please do not translate Face. */
- _("Could not load Face header file %s: %s"));
- sw_set_header_from_path(message, "X-Face", libbalsa_identity_get_x_face_path(ident),
- /* Translators: please do not translate Face. */
- _("Could not load X-Face header file %s: %s"));
+ if (bsmsg->req_mdn)
+ libbalsa_message_set_dispnotify(message, ia);
- libbalsa_message_set_references(message, bsmsg->references);
- bsmsg->references = NULL; /* steal it */
- if (bsmsg->in_reply_to != NULL) {
- libbalsa_message_set_in_reply_to(message,
- g_list_prepend(NULL,
- g_strdup(bsmsg->in_reply_to)));
- }
+ sw_set_header_from_path(message, "Face", libbalsa_identity_get_face_path(ident),
+ /* Translators: please do not translate Face. */
+ _("Could not load Face header file %s: %s"));
+ sw_set_header_from_path(message, "X-Face", libbalsa_identity_get_x_face_path(ident),
+ /* Translators: please do not translate Face. */
+ _("Could not load X-Face header file %s: %s"));
- body = libbalsa_message_body_new(message);
+ libbalsa_message_set_references(message, bsmsg->references);
+ bsmsg->references = NULL; /* steal it */
- buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bsmsg->text));
- gtk_text_buffer_get_bounds(buffer, &start, &end);
+ if (bsmsg->in_reply_to != NULL) {
+ libbalsa_message_set_in_reply_to(message,
+ g_list_prepend(NULL,
+ g_strdup(bsmsg->in_reply_to)));
+ }
- if (bsmsg->flow) {
- /* Copy the message text to a new buffer: */
- GtkTextTagTable *table;
+ body = libbalsa_message_body_new(message);
- table = gtk_text_buffer_get_tag_table(buffer);
- new_buffer = gtk_text_buffer_new(table);
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bsmsg->text));
+ gtk_text_buffer_get_bounds(buffer, &start, &end);
- tmp = gtk_text_iter_get_text(&start, &end);
- gtk_text_buffer_set_text(new_buffer, tmp, -1);
- g_free(tmp);
+ if (bsmsg->flow) {
+ /* Copy the message text to a new buffer: */
+ GtkTextTagTable *table;
+ char *text;
- /* Remove spaces before a newline: */
- gtk_text_buffer_get_bounds(new_buffer, &start, &end);
- libbalsa_unwrap_buffer(new_buffer, &start, -1);
- gtk_text_buffer_get_bounds(new_buffer, &start, &end);
- }
-
- /* Copy the buffer text to the message: */
- body->buffer = gtk_text_iter_get_text(&start, &end);
- if (new_buffer)
- g_object_unref(new_buffer);
-
- if (bsmsg->send_mp_alt)
- body->html_buffer =
- libbalsa_text_to_html(LIBBALSA_MESSAGE_GET_SUBJECT(message), body->buffer,
- bsmsg->spell_check_lang);
- if (bsmsg->flow)
- body->buffer =
- libbalsa_wrap_rfc2646(body->buffer, balsa_app.wraplength,
- TRUE, FALSE, TRUE);
-
- /* Ildar reports that, when a message contains both text/plain and
- * text/html parts, some broken MUAs use the charset from the
- * text/plain part to display the text/html part; the latter is
- * encoded as UTF-8 by add_mime_body_plain (send.c), so we'll use
- * the same encoding for the text/plain part.
- * https://bugzilla.gnome.org/show_bug.cgi?id=580704 */
- body->charset =
- g_strdup(bsmsg->send_mp_alt ?
- "UTF-8" : sw_required_charset(bsmsg, body->buffer));
- libbalsa_message_append_part(message, body);
+ table = gtk_text_buffer_get_tag_table(buffer);
+ new_buffer = gtk_text_buffer_new(table);
+
+ text = gtk_text_iter_get_text(&start, &end);
+ gtk_text_buffer_set_text(new_buffer, text, -1);
+ g_free(text);
+
+ /* Remove spaces before a newline: */
+ gtk_text_buffer_get_bounds(new_buffer, &start, &end);
+ libbalsa_unwrap_buffer(new_buffer, &start, -1);
+ gtk_text_buffer_get_bounds(new_buffer, &start, &end);
+ }
+
+ /* Copy the buffer text to the message: */
+ body->buffer = gtk_text_iter_get_text(&start, &end);
+ if (new_buffer)
+ g_object_unref(new_buffer);
+
+ if (bsmsg->send_mp_alt)
+ body->html_buffer =
+ libbalsa_text_to_html(LIBBALSA_MESSAGE_GET_SUBJECT(message), body->buffer,
+ bsmsg->spell_check_lang);
+ if (bsmsg->flow)
+ body->buffer =
+ libbalsa_wrap_rfc2646(body->buffer, balsa_app.wraplength,
+ TRUE, FALSE, TRUE);
+
+ /* Ildar reports that, when a message contains both text/plain and
+ * text/html parts, some broken MUAs use the charset from the
+ * text/plain part to display the text/html part; the latter is
+ * encoded as UTF-8 by add_mime_body_plain (send.c), so we'll use
+ * the same encoding for the text/plain part.
+ * https://bugzilla.gnome.org/show_bug.cgi?id=580704 */
+ body->charset =
+ g_strdup(bsmsg->send_mp_alt ?
+ "UTF-8" : sw_required_charset(bsmsg, body->buffer));
+ libbalsa_message_append_part(message, body);
+
+ if (balsa_app.has_openpgp || balsa_app.has_smime) {
+ libbalsa_message_set_gpg_mode(message,
+ (bsmsg->gpg_mode & LIBBALSA_PROTECT_MODE) != 0 ? bsmsg->gpg_mode : 0);
+ libbalsa_message_set_attach_pubkey(message, bsmsg->attach_pubkey);
+ libbalsa_message_set_identity(message, ident);
+ } else {
+ libbalsa_message_set_gpg_mode(message, 0);
+ libbalsa_message_set_attach_pubkey(message, FALSE);
+ }
+ }
/* add attachments */
- if (bsmsg->tree_view)
+ if (bsmsg->tree_view != NULL) {
gtk_tree_model_foreach(BALSA_MSG_ATTACH_MODEL(bsmsg),
attachment2message, message);
+ }
headers->date = time(NULL);
- if (balsa_app.has_openpgp || balsa_app.has_smime) {
- libbalsa_message_set_gpg_mode(message,
- (bsmsg->gpg_mode & LIBBALSA_PROTECT_MODE) != 0 ? bsmsg->gpg_mode : 0);
- libbalsa_message_set_attach_pubkey(message, bsmsg->attach_pubkey);
- libbalsa_message_set_identity(message, ident);
- } else {
- libbalsa_message_set_gpg_mode(message, 0);
- libbalsa_message_set_attach_pubkey(message, FALSE);
- }
/* remember the parent window */
g_object_set_data(G_OBJECT(message), "parent-window",
@@ -5475,7 +5430,6 @@ send_message_handler(BalsaSendmsg * bsmsg, gboolean queue_only)
LibBalsaMsgCreateResult result;
LibBalsaMessage *message;
LibBalsaMailbox *fcc;
- LibBalsaMailbox *parent_mailbox = NULL;
GtkTreeIter iter;
GError * error = NULL;
@@ -5551,11 +5505,6 @@ send_message_handler(BalsaSendmsg * bsmsg, gboolean queue_only)
_("sending message with GPG mode %d"),
libbalsa_message_get_gpg_mode(message));
- if (bsmsg->type == SEND_RESEND)
- parent_mailbox = libbalsa_message_get_mailbox(bsmsg->parent_message);
- if (parent_mailbox != NULL)
- libbalsa_mailbox_lock_store(parent_mailbox);
-
if(queue_only)
result = libbalsa_message_queue(message, balsa_app.outbox, fcc,
libbalsa_identity_get_smtp_server(bsmsg->ident),
@@ -5567,10 +5516,6 @@ send_message_handler(BalsaSendmsg * bsmsg, gboolean queue_only)
balsa_app.send_progress_dialog,
GTK_WINDOW(balsa_app.main_window),
bsmsg->flow, &error);
-
- if (parent_mailbox != NULL)
- libbalsa_mailbox_unlock_store(parent_mailbox);
-
if (result == LIBBALSA_MESSAGE_CREATE_OK) {
if (bsmsg->parent_message != NULL) {
LibBalsaMailbox *mailbox = libbalsa_message_get_mailbox(bsmsg->parent_message);
@@ -6552,8 +6497,7 @@ sendmsg_window_new_from_list(LibBalsaMailbox * mailbox,
switch(type) {
case SEND_FORWARD_ATTACH:
case SEND_FORWARD_INLINE:
- bsmsg = sendmsg_window_forward(mailbox, msgno,
- type == SEND_FORWARD_ATTACH);
+ bsmsg = sendmsg_window_forward(mailbox, msgno, type);
break;
default:
g_assert_not_reached(); /* since it hardly makes sense... */
@@ -6719,8 +6663,7 @@ sendmsg_window_set_title(BalsaSendmsg * bsmsg)
break;
case SEND_RESEND:
- title_format = _("Resend message to %s: %s");
- subject_string = LIBBALSA_MESSAGE_GET_SUBJECT(bsmsg->parent_message);
+ title_format = _("Resend message to %s");
break;
default:
@@ -6732,7 +6675,7 @@ sendmsg_window_set_title(BalsaSendmsg * bsmsg)
to_string = internet_address_list_to_string(list, NULL, FALSE);
g_object_unref(list);
- if (subject_string == NULL)
+ if (bsmsg->subject[1] != NULL)
subject_string = gtk_entry_get_text(GTK_ENTRY(bsmsg->subject[1]));
title = g_strdup_printf(title_format, to_string ? to_string : "", subject_string);
@@ -7177,41 +7120,67 @@ sendmsg_window_reply_embedded(LibBalsaMessageBody *part,
}
BalsaSendmsg*
-sendmsg_window_forward(LibBalsaMailbox *mailbox, guint msgno,
- gboolean attach)
+sendmsg_window_forward(LibBalsaMailbox *mailbox, guint msgno, SendType send_type)
{
- LibBalsaMessage *message =
- libbalsa_mailbox_get_message(mailbox, msgno);
- SendType send_type = attach ? SEND_FORWARD_ATTACH : SEND_FORWARD_INLINE;
- BalsaSendmsg *bsmsg = sendmsg_window_new(send_type);
+ LibBalsaMessage *message;
+ BalsaSendmsg *bsmsg;
- g_assert(message);
+ g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), NULL);
+ message = libbalsa_mailbox_get_message(mailbox, msgno);
+ g_return_val_if_fail(LIBBALSA_IS_MESSAGE(message), NULL);
- if (attach) {
- if(!attach_message(bsmsg, message))
- balsa_information_parented(GTK_WINDOW(bsmsg->window),
- LIBBALSA_INFORMATION_WARNING,
- _("Attaching message failed.\n"
- "Possible reason: not enough temporary space"));
- bsmsg->state = SENDMSG_STATE_CLEAN;
- bsmsg_set_subject_from_body(bsmsg, libbalsa_message_get_body_list(message), bsmsg->ident);
- } else {
- bsm_prepare_for_setup(message);
- fill_body_from_message(bsmsg, message, QUOTE_NOPREFIX);
- bsm_finish_setup(bsmsg, libbalsa_message_get_body_list(message));
+ bsmsg = sendmsg_window_new(send_type);
+
+ switch (send_type) {
+ case SEND_FORWARD_ATTACH:
+ if (!attach_message(bsmsg, message)) {
+ balsa_information_parented(GTK_WINDOW(bsmsg->window),
+ LIBBALSA_INFORMATION_WARNING,
+ _("Attaching message failed.\n"
+ "Possible reason: not enough temporary space"));
+ }
+ bsmsg->state = SENDMSG_STATE_CLEAN;
+ bsmsg_set_subject_from_body(bsmsg, libbalsa_message_get_body_list(message), bsmsg->ident);
+ if (libbalsa_identity_get_sig_whenforward(bsmsg->ident))
+ insert_initial_sig(bsmsg);
+
+ break;
+
+ case SEND_RESEND:
+ if (!attach_message(bsmsg, message)) {
+ balsa_information_parented(GTK_WINDOW(bsmsg->window),
+ LIBBALSA_INFORMATION_WARNING,
+ _("Attaching message failed.\n"
+ "Possible reason: not enough temporary space"));
+ }
+
+ break;
+
+ case SEND_FORWARD_INLINE:
+ {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(bsmsg->text));
+ GtkTextIter pos;
+
+ bsm_prepare_for_setup(message);
+ fill_body_from_message(bsmsg, message, QUOTE_NOPREFIX);
+ bsm_finish_setup(bsmsg, libbalsa_message_get_body_list(message));
+
+ if (libbalsa_identity_get_sig_whenforward(bsmsg->ident))
+ insert_initial_sig(bsmsg);
+
+ gtk_text_buffer_get_start_iter(buffer, &pos);
+ gtk_text_buffer_place_cursor(buffer, &pos);
+ gtk_text_buffer_insert_at_cursor(buffer, "\n", 1);
+ gtk_text_buffer_get_start_iter(buffer, &pos);
+ gtk_text_buffer_place_cursor(buffer, &pos);
+ }
+
+ break;
+
+ default:
+ g_assert_not_reached();
}
- if (libbalsa_identity_get_sig_whenforward(bsmsg->ident))
- insert_initial_sig(bsmsg);
- if(!attach) {
- GtkTextBuffer *buffer =
- gtk_text_view_get_buffer(GTK_TEXT_VIEW(bsmsg->text));
- GtkTextIter pos;
- gtk_text_buffer_get_start_iter(buffer, &pos);
- gtk_text_buffer_place_cursor(buffer, &pos);
- gtk_text_buffer_insert_at_cursor(buffer, "\n", 1);
- gtk_text_buffer_get_start_iter(buffer, &pos);
- gtk_text_buffer_place_cursor(buffer, &pos);
- }
+
return bsmsg;
}
@@ -7220,6 +7189,7 @@ sendmsg_window_continue(LibBalsaMailbox * mailbox, guint msgno)
{
LibBalsaMessage *message =
libbalsa_mailbox_get_message(mailbox, msgno);
+ gboolean resending;
BalsaSendmsg *bsmsg;
const gchar *postpone_hdr;
GList *list, *refs = NULL;
@@ -7234,7 +7204,9 @@ sendmsg_window_continue(LibBalsaMailbox * mailbox, guint msgno)
return NULL;
}
- bsmsg = sendmsg_window_new(SEND_CONTINUE);
+ resending = libbalsa_message_get_user_header(message, "X-Balsa-Resend") != NULL;
+ bsmsg = sendmsg_window_new(resending ? SEND_RESEND : SEND_CONTINUE);
+
bsmsg->is_continue = TRUE;
bsm_prepare_for_setup(message);
bsmsg->draft_message = message;
@@ -7243,89 +7215,67 @@ sendmsg_window_continue(LibBalsaMailbox * mailbox, guint msgno)
set_identity(bsmsg, message);
setup_headers_from_message(bsmsg, message);
- libbalsa_address_view_set_from_list(bsmsg->replyto_view,
- "Reply To:",
- libbalsa_message_get_headers(message)->reply_to);
- in_reply_to = libbalsa_message_get_in_reply_to(message);
- if (in_reply_to != NULL)
- bsmsg->in_reply_to =
- g_strconcat("<", in_reply_to->data, ">", NULL);
-
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-Crypto")))
- bsmsg_setup_gpg_ui_by_mode(bsmsg, atoi(postpone_hdr));
- postpone_hdr = libbalsa_message_get_user_header(message, "X-Balsa-Att-Pubkey");
- if (postpone_hdr != NULL) {
- sw_action_set_active(bsmsg, "attpubkey", atoi(postpone_hdr) != 0);
- }
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-MDN")))
- sw_action_set_active(bsmsg, "request-mdn", atoi(postpone_hdr) != 0);
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-DSN")))
- sw_action_set_active(bsmsg, "request-dsn", atoi(postpone_hdr) != 0);
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-Lang"))) {
- GtkWidget *langs =
- gtk_menu_item_get_submenu(GTK_MENU_ITEM
- (bsmsg->current_language_menu));
- GList *children =
- gtk_container_get_children(GTK_CONTAINER(langs));
- set_locale(bsmsg, postpone_hdr);
- for (list = children; list; list = list->next) {
- GtkCheckMenuItem *menu_item = list->data;
- const gchar *lang;
-
- lang = g_object_get_data(G_OBJECT(menu_item),
- BALSA_LANGUAGE_MENU_LANG);
- if (strcmp(lang, postpone_hdr) == 0)
- gtk_check_menu_item_set_active(menu_item, TRUE);
+ if (resending) {
+ continue_body(bsmsg, message);
+ } else {
+ libbalsa_address_view_set_from_list(bsmsg->replyto_view,
+ "Reply To:",
+ libbalsa_message_get_headers(message)->reply_to);
+ in_reply_to = libbalsa_message_get_in_reply_to(message);
+ if (in_reply_to != NULL)
+ bsmsg->in_reply_to =
+ g_strconcat("<", in_reply_to->data, ">", NULL);
+
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-Crypto")))
+ bsmsg_setup_gpg_ui_by_mode(bsmsg, atoi(postpone_hdr));
+ postpone_hdr = libbalsa_message_get_user_header(message, "X-Balsa-Att-Pubkey");
+ if (postpone_hdr != NULL) {
+ sw_action_set_active(bsmsg, "attpubkey", atoi(postpone_hdr) != 0);
}
- g_list_free(children);
- }
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-Format")))
- sw_action_set_active(bsmsg, "flowed", strcmp(postpone_hdr, "Fixed"));
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-MP-Alt")))
- sw_action_set_active(bsmsg, "send-html", !strcmp(postpone_hdr, "yes"));
- if ((postpone_hdr =
- libbalsa_message_get_user_header(message, "X-Balsa-Send-Type")))
- bsmsg->type = atoi(postpone_hdr);
-
- for (list = libbalsa_message_get_references(message); list != NULL; list = list->next)
- refs = g_list_prepend(refs, g_strdup(list->data));
- bsmsg->references = g_list_reverse(refs);
-
- continue_body(bsmsg, message);
- bsm_finish_setup(bsmsg, libbalsa_message_get_body_list(message));
- g_idle_add((GSourceFunc) sw_grab_focus_to_text,
- g_object_ref(bsmsg->text));
- return bsmsg;
-}
-
-/*
- * sendmsg_window_resend
- *
- * Opens a small compose window for resending the message to new
- * recipient(s).
- *
- * https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.6
- */
-BalsaSendmsg *
-sendmsg_window_resend(LibBalsaMailbox *mailbox, guint msgno)
-{
- LibBalsaMessage *message;
- BalsaSendmsg *bsmsg;
-
- g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), NULL);
- message = libbalsa_mailbox_get_message(mailbox, msgno);
- g_return_val_if_fail(LIBBALSA_IS_MESSAGE(message), NULL);
-
- bsmsg = sendmsg_window_new(SEND_RESEND);
- bsmsg->parent_message = message;
- libbalsa_mailbox_open(mailbox, NULL);
- set_identity(bsmsg, message);
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-MDN")))
+ sw_action_set_active(bsmsg, "request-mdn", atoi(postpone_hdr) != 0);
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-DSN")))
+ sw_action_set_active(bsmsg, "request-dsn", atoi(postpone_hdr) != 0);
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-Lang"))) {
+ GtkWidget *langs =
+ gtk_menu_item_get_submenu(GTK_MENU_ITEM
+ (bsmsg->current_language_menu));
+ GList *children =
+ gtk_container_get_children(GTK_CONTAINER(langs));
+ set_locale(bsmsg, postpone_hdr);
+ for (list = children; list; list = list->next) {
+ GtkCheckMenuItem *menu_item = list->data;
+ const gchar *lang;
+
+ lang = g_object_get_data(G_OBJECT(menu_item),
+ BALSA_LANGUAGE_MENU_LANG);
+ if (strcmp(lang, postpone_hdr) == 0)
+ gtk_check_menu_item_set_active(menu_item, TRUE);
+ }
+ g_list_free(children);
+ }
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-Format")))
+ sw_action_set_active(bsmsg, "flowed", strcmp(postpone_hdr, "Fixed"));
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-MP-Alt")))
+ sw_action_set_active(bsmsg, "send-html", !strcmp(postpone_hdr, "yes"));
+ if ((postpone_hdr =
+ libbalsa_message_get_user_header(message, "X-Balsa-Send-Type")))
+ bsmsg->type = atoi(postpone_hdr);
+
+ for (list = libbalsa_message_get_references(message); list != NULL; list = list->next)
+ refs = g_list_prepend(refs, g_strdup(list->data));
+ bsmsg->references = g_list_reverse(refs);
+
+ continue_body(bsmsg, message);
+ bsm_finish_setup(bsmsg, libbalsa_message_get_body_list(message));
+ g_idle_add((GSourceFunc) sw_grab_focus_to_text, g_object_ref(bsmsg->text));
+ }
return bsmsg;
}
diff --git a/src/sendmsg-window.h b/src/sendmsg-window.h
index 0ab21e7ae..d1125ec3b 100644
--- a/src/sendmsg-window.h
+++ b/src/sendmsg-window.h
@@ -114,10 +114,8 @@ G_BEGIN_DECLS
BalsaSendmsg *sendmsg_window_reply_embedded(LibBalsaMessageBody *part,
SendType reply_type);
- BalsaSendmsg *sendmsg_window_resend(LibBalsaMailbox *mailbox, guint msgno);
-
BalsaSendmsg *sendmsg_window_forward(LibBalsaMailbox *,
- guint msgno, gboolean attach);
+ guint msgno, SendType send_type);
BalsaSendmsg *sendmsg_window_continue(LibBalsaMailbox *,
guint msgno);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]