Made "Reply to author" send an email reply to a news posting.
authorSergey Vlasov <vsu@users.sourceforge.net>
Sat, 19 May 2001 18:22:38 +0000 (18:22 +0000)
committerSergey Vlasov <vsu@users.sourceforge.net>
Sat, 19 May 2001 18:22:38 +0000 (18:22 +0000)
ChangeLog.claws
src/account.c
src/account.h
src/compose.c

index 3713dd0..3357702 100644 (file)
@@ -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
index b5cd18f..a259c56 100644 (file)
@@ -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;
index baf0fef..3632bc2 100644 (file)
@@ -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);
index 49506c7..0b5d400 100644 (file)
@@ -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;