enable NNTP over SSL
authorPaul Mangan <paul@claws-mail.org>
Mon, 25 Mar 2002 09:37:38 +0000 (09:37 +0000)
committerPaul Mangan <paul@claws-mail.org>
Mon, 25 Mar 2002 09:37:38 +0000 (09:37 +0000)
AUTHORS
ChangeLog.claws
configure.in
src/account.c
src/news.c
src/nntp.c
src/nntp.h
src/prefs_account.c
src/prefs_account.h

diff --git a/AUTHORS b/AUTHORS
index dd87866..269ad2f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -136,3 +136,4 @@ contributors (beside the above; based on Changelog)
        Wilbert Berendsen
        Bob Woodside
        Stefaan Eeckels
+       Pascal Jermini
index 8468bd7..fdfb913 100644 (file)
@@ -1,3 +1,12 @@
+2002-03-25 [paul]      0.7.4claws40
+
+       * src/account.c
+         src/news.c
+         src/nntp.[ch]
+         src/prefs_account.[ch]
+               enable NNTP over SSL. patch submitted by
+               Pascal Jermini <pascal@infinity.hn.org>
+
 2002-03-24 [paul]      0.7.4claws39
 
        * src/prefs_common.c
index 1e19c44..de76bf6 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws39
+EXTRA_VERSION=claws40
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 7a953f8..bfbf656 100644 (file)
@@ -752,7 +752,8 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
                             ac_prefs->protocol == A_IMAP4 ?
                             (ac_prefs->ssl_imap ? "IMAP4 (SSL)" : "IMAP4") :
                             ac_prefs->protocol == A_LOCAL ? "Local" :
-                            ac_prefs->protocol == A_NNTP ? "NNTP"  :  "";
+                            ac_prefs->protocol == A_NNTP ? 
+                                 (ac_prefs->ssl_nntp ? "NNTP (SSL)"  :  "NNTP") : "";
 #else
        text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3" :
                             ac_prefs->protocol == A_APOP  ? "POP3 (APOP)" :
index 9bff6fc..6e46ecc 100644 (file)
 #include "alertpanel.h"
 
 #define NNTP_PORT      119
+#if USE_SSL
+#define NNTPS_PORT 563
+#endif
 
 static void news_folder_init            (Folder        *folder,
                                          const gchar   *name,
                                          const gchar   *path);
 
+#if USE_SSL
+static Session *news_session_new        (const gchar   *server,
+                                         gushort        port,
+                                         const gchar   *userid,
+                                         const gchar   *passwd, gboolean use_ssl);
+#else
 static Session *news_session_new        (const gchar   *server,
                                          gushort        port,
                                          const gchar   *userid,
                                          const gchar   *passwd);
+#endif
 
 static gint news_get_article_cmd        (NNTPSession   *session,
                                          const gchar   *cmd,
@@ -120,8 +130,13 @@ static void news_folder_init(Folder *folder, const gchar *name,
        folder->remove_msg   = news_remove_msg;
 }
 
+#if USE_SSL
+static Session *news_session_new(const gchar *server, gushort port,
+                                const gchar *userid, const gchar *passwd, gboolean use_ssl)
+#else
 static Session *news_session_new(const gchar *server, gushort port,
                                 const gchar *userid, const gchar *passwd)
+#endif
 {
        gchar buf[NNTPBUFSIZE];
        NNTPSession *session;
@@ -132,9 +147,18 @@ static Session *news_session_new(const gchar *server, gushort port,
        log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
 
        if (userid && passwd)
+#if USE_SSL
+               nntp_sock = nntp_open_auth(server, port, buf, userid, passwd, use_ssl);
+#else
                nntp_sock = nntp_open_auth(server, port, buf, userid, passwd);
+#endif
        else
+#if USE_SSL
+               nntp_sock = nntp_open(server, port, buf, use_ssl);
+#else
                nntp_sock = nntp_open(server, port, buf);
+#endif
+
        if (nntp_sock == NULL)
                return NULL;
 
@@ -167,11 +191,22 @@ static Session *news_session_new_for_folder(Folder *folder)
        PrefsAccount *ac;
        const gchar *userid = NULL;
        gchar *passwd = NULL;
+       int port;
 
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(folder->account != NULL, NULL);
 
        ac = folder->account;
+
+#if USE_SSL
+       if (ac->set_nntpport) {
+                port = ac->nntpport;
+       } else {
+                port = ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
+       }
+#else
+       port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
+#endif
        if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
                userid = ac->userid;
                if (ac->passwd && ac->passwd[0])
@@ -181,9 +216,15 @@ static Session *news_session_new_for_folder(Folder *folder)
                                                             userid);
        }
 
+#if USE_SSL
        session = news_session_new(ac->nntp_server,
-                                  ac->set_nntpport ? ac->nntpport : NNTP_PORT,
+                                  port, 
+                                  userid, passwd, ac->ssl_nntp);
+#else
+       session = news_session_new(ac->nntp_server,
+                                  port, 
                                   userid, passwd);
+#endif
        g_free(passwd);
 
        return session;
index 458ffe7..a15921f 100644 (file)
@@ -28,6 +28,7 @@
 #include "intl.h"
 #include "nntp.h"
 #include "socket.h"
+#include "ssl.h"
 #include "utils.h"
 
 static gint verbose = 1;
@@ -43,7 +44,11 @@ static gint nntp_gen_command (NNTPSockInfo   *sock,
                                 const gchar    *format,
                                 ...);
 
+#if USE_SSL
+NNTPSockInfo *nntp_open(const gchar *server, gushort port, gchar *buf, gboolean use_ssl)
+#else
 NNTPSockInfo *nntp_open(const gchar *server, gushort port, gchar *buf)
+#endif
 {
        SockInfo *sock;
        NNTPSockInfo *nntp_sock;
@@ -53,6 +58,14 @@ NNTPSockInfo *nntp_open(const gchar *server, gushort port, gchar *buf)
                            server, port);
                return NULL;
        }
+
+#if USE_SSL
+       if (use_ssl && !ssl_init_socket(sock)) {
+                sock_close(sock);
+                return NULL;
+       }
+#endif
+       
        nntp_sock = g_new0(NNTPSockInfo, 1);
        nntp_sock->sock = sock;
 
@@ -65,12 +78,22 @@ NNTPSockInfo *nntp_open(const gchar *server, gushort port, gchar *buf)
        }
 }
 
+#if USE_SSL
+NNTPSockInfo *nntp_open_auth(const gchar *server, gushort port, gchar *buf,
+                            const gchar *userid, const gchar *passwd, gboolean use_ssl)
+#else
 NNTPSockInfo *nntp_open_auth(const gchar *server, gushort port, gchar *buf,
                             const gchar *userid, const gchar *passwd)
+#endif
 {
        NNTPSockInfo *sock;
 
+#if USE_SSL
+       sock = nntp_open(server, port, buf, use_ssl);
+#else
        sock = nntp_open(server, port, buf);
+#endif
+
        if (!sock) return NULL;
 
        sock->userid = g_strdup(userid);
index 3063c08..4ebfe3f 100644 (file)
@@ -45,14 +45,31 @@ struct _NNTPSockInfo
 
 #define NNTPBUFSIZE    8192
 
+#if USE_SSL
+NNTPSockInfo *nntp_open                (const gchar    *server,
+                                gushort         port,
+                                gchar          *buf,
+                                gboolean use_ssl);
+#else
 NNTPSockInfo *nntp_open                (const gchar    *server,
                                 gushort         port,
                                 gchar          *buf);
+#endif
+
+#if USE_SSL
+NNTPSockInfo *nntp_open_auth   (const gchar    *server,
+                                gushort         port,
+                                gchar          *buf,
+                                const gchar    *userid,
+                                const gchar    *passwd,
+                                gboolean use_ssl);
+#else
 NNTPSockInfo *nntp_open_auth   (const gchar    *server,
                                 gushort         port,
                                 gchar          *buf,
                                 const gchar    *userid,
                                 const gchar    *passwd);
+#endif
 void nntp_close                        (NNTPSockInfo   *sock);
 gint nntp_group                        (NNTPSockInfo   *sock,
                                 const gchar    *group,
index 25b62ce..a3c4841 100644 (file)
@@ -141,6 +141,7 @@ static struct SSLPrefs {
        GtkWidget *receive_frame;
        GtkWidget *pop_chkbtn;
        GtkWidget *imap_chkbtn;
+       GtkWidget *nntp_chkbtn;
 
        GtkWidget *send_frame;
        GtkWidget *smtp_nossl_radiobtn;
@@ -362,6 +363,8 @@ static PrefParam param[] = {
         &ssl.pop_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
        {"ssl_imap", "FALSE", &tmp_ac_prefs.ssl_imap, P_BOOL,
         &ssl.imap_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
+       {"ssl_nntp", "FALSE", &tmp_ac_prefs.ssl_nntp, P_BOOL,
+        &ssl.nntp_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
 #endif /* USE_SSL */
 
        /* Advanced */
@@ -1478,6 +1481,7 @@ static void prefs_account_ssl_create(void)
        GtkWidget *vbox2;
        GtkWidget *pop_chkbtn;
        GtkWidget *imap_chkbtn;
+       GtkWidget *nntp_chkbtn;
 
        GtkWidget *send_frame;
        GtkWidget *vbox3;
@@ -1501,6 +1505,8 @@ static void prefs_account_ssl_create(void)
                           _("Use SSL for POP3 connection"));
        PACK_CHECK_BUTTON (vbox2, imap_chkbtn,
                           _("Use SSL for IMAP4 connection"));
+       PACK_CHECK_BUTTON (vbox2, nntp_chkbtn,
+                          _("Use SSL for NNTP connection"));
 
        PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
 
@@ -1538,6 +1544,7 @@ static void prefs_account_ssl_create(void)
        ssl.receive_frame = receive_frame;
        ssl.pop_chkbtn    = pop_chkbtn;
        ssl.imap_chkbtn   = imap_chkbtn;
+       ssl.nntp_chkbtn   = nntp_chkbtn;
 
        ssl.send_frame                = send_frame;
        ssl.smtp_nossl_radiobtn       = smtp_nossl_radiobtn;
@@ -1963,9 +1970,10 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(receive.imap_frame, FALSE);
                gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
 #if USE_SSL
-               gtk_widget_set_sensitive(ssl.receive_frame, FALSE);
+               gtk_widget_set_sensitive(ssl.receive_frame, TRUE);
                gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
+               gtk_widget_set_sensitive(ssl.nntp_chkbtn, TRUE);
                gtk_widget_set_sensitive(ssl.send_frame, FALSE);
 #endif
                gtk_widget_hide(advanced.popport_hbox);
@@ -2023,6 +2031,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(ssl.receive_frame, FALSE);
                gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
+               gtk_widget_set_sensitive(ssl.nntp_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.send_frame, TRUE);
 #endif
                gtk_widget_hide(advanced.popport_hbox);
@@ -2082,6 +2091,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(ssl.receive_frame, TRUE);
                gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.imap_chkbtn, TRUE);
+               gtk_widget_set_sensitive(ssl.nntp_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.send_frame, TRUE);
 #endif
                gtk_widget_hide(advanced.popport_hbox);
@@ -2142,6 +2152,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(ssl.receive_frame, TRUE);
                gtk_widget_set_sensitive(ssl.pop_chkbtn, TRUE);
                gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
+               gtk_widget_set_sensitive(ssl.nntp_chkbtn, FALSE);
                gtk_widget_set_sensitive(ssl.send_frame, TRUE);
 #endif
                gtk_widget_show(advanced.popport_hbox);
index 45f1d7f..6215fd9 100644 (file)
@@ -94,6 +94,7 @@ struct _PrefsAccount
        /* SSL */
        gboolean ssl_pop;
        gboolean ssl_imap;
+       gboolean ssl_nntp;
        SSLSMTPType ssl_smtp;
 #endif /* USE_SSL */