From 64c782df3fde2c2cd0bed39823d5332f0c9fcd38 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Sat, 19 May 2001 18:22:38 +0000 Subject: [PATCH] Made "Reply to author" send an email reply to a news posting. --- ChangeLog.claws | 10 ++++++++-- src/account.c | 23 +++++++++++++++++++++++ src/account.h | 1 + src/compose.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index 3713dd04b..335770274 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -4,8 +4,12 @@ COMPOSE_REPLY_TO_AUTHOR, COMPOSE_REPLY_TO_AUTHOR_WITH_QUOTE, COMPOSE_REPLY_TO_AUTHOR_WITHOUT_QUOTE. - * src/compose.c (compose_reply): new argument to_author; all - callers changed. + * src/compose.c + (compose_send): move some code into a new function: + (compose_current_mail_account): new function. + (compose_reply): new argument to_author, all callers changed; if + to_author==TRUE and account->protocol==A_NNTP, find and use an + appropriate mail account for replying. (compose_reply_set_entry): new argument to_author; ignore compose->replyto if to_author==TRUE. @@ -17,6 +21,8 @@ (summary_set_menu_sensitive): enable/disable it. (summary_reply_cb): handle it. + * src/account.c (account_find_mail_from_address): new function. + 2001-05-18 [paul] 0.4.99claws1 diff --git a/src/account.c b/src/account.c index b5cd18f6f..a259c5643 100644 --- a/src/account.c +++ b/src/account.c @@ -167,6 +167,29 @@ PrefsAccount *account_find_from_smtp_server(const gchar *address, return NULL; } +/** + * account_find_mail_from_address: + * @address: Email address string. + * + * Find a mail (not news) account with the specified email address. + * + * Return value: The found account, or NULL if not found. + **/ +PrefsAccount *account_find_mail_from_address(const gchar *address) +{ + GList *cur; + PrefsAccount *ac; + + for (cur = account_list; cur != NULL; cur = cur->next) { + ac = (PrefsAccount *)cur->data; + if (ac->protocol != A_NNTP && + !strcmp2(address, ac->address)) + return ac; + } + + return NULL; +} + PrefsAccount *account_find_from_id(gint id) { GList *cur; diff --git a/src/account.h b/src/account.h index baf0fef91..3632bc213 100644 --- a/src/account.h +++ b/src/account.h @@ -35,6 +35,7 @@ void account_save_config_all (void); PrefsAccount *account_find_from_smtp_server (const gchar *address, const gchar *smtp_server); +PrefsAccount *account_find_mail_from_address (const gchar *address); PrefsAccount *account_find_from_id (gint id); void account_set_menu (void); diff --git a/src/compose.c b/src/compose.c index 49506c73b..0b5d400d2 100644 --- a/src/compose.c +++ b/src/compose.c @@ -153,6 +153,7 @@ static void compose_attach_append (Compose *compose, static void compose_wrap_line (Compose *compose); static void compose_set_title (Compose *compose); +static PrefsAccount *compose_current_mail_account(void); /* static gint compose_send (Compose *compose); */ static gint compose_write_to_file (Compose *compose, const gchar *file, @@ -468,6 +469,7 @@ void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all, { Compose *compose; PrefsAccount *account; + PrefsAccount *reply_account; GtkSText *text; g_return_if_fail(msginfo != NULL); @@ -477,10 +479,20 @@ void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all, if (!account) account = cur_account; g_return_if_fail(account != NULL); + if (to_author && account->protocol == A_NNTP) { + reply_account = + account_find_mail_from_address(account->address); + if (!reply_account) + reply_account = compose_current_mail_account(); + if (!reply_account) + return; + } else + reply_account = account; + MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED); MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED); - compose = compose_create(account); + compose = compose_create(reply_account); compose->mode = COMPOSE_REPLY; if (compose_parse_header(compose, msginfo) < 0) return; @@ -1390,6 +1402,33 @@ static void compose_set_title(Compose *compose) g_free(str); } +/** + * compose_current_mail_account: + * + * Find a current mail account (the currently selected account, or the + * default account, if a news account is currently selected). If a + * mail account cannot be found, display an error message. + * + * Return value: Mail account, or NULL if not found. + **/ +static PrefsAccount * +compose_current_mail_account(void) +{ + PrefsAccount *ac; + + if (cur_account && cur_account->protocol != A_NNTP) + ac = cur_account; + else { + ac = account_get_default(); + if (!ac || ac->protocol == A_NNTP) { + alertpanel_error(_("Account for sending mail is not specified.\n" + "Please select a mail account before sending.")); + return NULL; + } + } + return ac; +} + gint compose_send(Compose *compose) { gchar tmp[MAXPATHLEN + 1]; @@ -1438,13 +1477,9 @@ gint compose_send(Compose *compose) ac = compose->account; else if (compose->orig_account->protocol != A_NNTP) ac = compose->orig_account; - else if (cur_account && cur_account->protocol != A_NNTP) - ac = cur_account; else { - ac = account_get_default(); - if (!ac || ac->protocol == A_NNTP) { - alertpanel_error(_("Account for sending mail is not specified.\n" - "Please select a mail account before sending.")); + ac = compose_current_mail_account(); + if (!ac) { unlink(tmp); lock = FALSE; return -1; -- 2.25.1