* src/mh.c
authorChristoph Hohmann <reboot@gmx.ch>
Mon, 7 Jan 2002 20:25:37 +0000 (20:25 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Mon, 7 Jan 2002 20:25:37 +0000 (20:25 +0000)
search for free message number, do not only rely
on last_num
* src/send.c
fix smtp auth and use extra account information
if available, if not use pop3 data instead
(closes bug #500341)
* src/ssl.[ch]
match coding style

ChangeLog.claws
configure.in
src/mh.c
src/send.c
src/ssl.c
src/ssl.h

index 469d4fa..20e1163 100644 (file)
@@ -1,3 +1,15 @@
+2002-01-07 [christoph] 0.6.6claws43
+
+       * src/mh.c
+               search for free message number, do not only rely
+               on last_num
+       * src/send.c
+               fix smtp auth and use extra account information
+               if available, if not use pop3 data instead
+               (closes bug #500341)            
+       * src/ssl.[ch]
+               match coding style
+
 2002-01-06 [alfons]    0.6.6claws42
 
        * src/mainwindow.c
index 22de1c4..4255c77 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws42
+EXTRA_VERSION=claws43
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index 42fcc1c..5d03a5f 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -131,10 +131,35 @@ gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
        return file;
 }
 
+gchar *mh_get_newmsg_filename(FolderItem *dest)
+{
+       gchar *destfile;
+       gchar *destpath;
+       gboolean found = FALSE;
+
+       destpath = folder_item_get_path(dest);
+       g_return_val_if_fail(destpath != NULL, NULL);
+       if (!is_dir_exist(destpath))
+               make_dir_hier(destpath);
+
+       do {
+               destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
+                                          dest->last_num + 1);
+               if(is_file_exist(destfile)) {
+                       dest->last_num++;
+                       g_free(destfile);
+               } else {
+                       found = TRUE;
+               }
+       } while(!found);
+       g_free(destpath);
+
+       return destfile;
+}
+
 gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
                gboolean remove_source)
 {
-       gchar *destpath;
        gchar *destfile;
 
        g_return_val_if_fail(dest != NULL, -1);
@@ -145,13 +170,8 @@ gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
                if (dest->last_num < 0) return -1;
        }
 
-       destpath = folder_item_get_path(dest);
-       g_return_val_if_fail(destpath != NULL, -1);
-       if (!is_dir_exist(destpath))
-               make_dir_hier(destpath);
-
-       destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
-                                  dest->last_num + 1);
+       destfile = mh_get_newmsg_filename(dest);
+       if(!destfile) return -1;
 
        if (link(file, destfile) < 0) {
                if (copy_file(file, destfile) < 0) {
@@ -204,8 +224,10 @@ gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                    msginfo->folder->path, G_DIR_SEPARATOR,
                    msginfo->msgnum, dest->path);
        srcfile = procmsg_get_message_file_path(msginfo);
-       destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
-                                  dest->last_num + 1);
+
+       destfile = mh_get_newmsg_filename(dest);
+       if(!destfile) return -1;
+
        g_free(destdir);
 
        if (move_file(srcfile, destfile) < 0) {
@@ -299,8 +321,8 @@ gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                            msginfo->msgnum, dest->path);
 
                srcfile = procmsg_get_message_file_path(msginfo);
-               destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
-                                          dest->last_num + 1);
+               destfile = mh_get_newmsg_filename(dest);
+               if(!destfile) return -1;
 
                if (move_file(srcfile, destfile) < 0) {
                        g_free(srcfile);
@@ -370,19 +392,16 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
                    msginfo->folder->path, G_DIR_SEPARATOR,
                    msginfo->msgnum, dest->path);
        srcfile = procmsg_get_message_file_path(msginfo);
-       destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
-                                  dest->last_num + 1);
-       g_free(destdir);
-
-       dest->op_count--;
-
-       if (is_file_exist(destfile)) {
-               g_warning(_("%s already exists."), destfile);
+       destfile = mh_get_newmsg_filename(dest);
+       if(!destfile) {
                g_free(srcfile);
-               g_free(destfile);
                if (fp) fclose(fp);
                return -1;
        }
+       
+       g_free(destdir);
+
+       dest->op_count--;
 
        if (copy_file(srcfile, destfile) < 0) {
                FILE_OP_ERROR(srcfile, "copy");
@@ -520,13 +539,9 @@ gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                            msginfo->msgnum, dest->path);
 
                srcfile = procmsg_get_message_file_path(msginfo);
-               destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
-                                          dest->last_num + 1);
-
-               if (is_file_exist(destfile)) {
-                       g_warning(_("%s already exists."), destfile);
+               destfile = mh_get_newmsg_filename(dest);
+               if(!destfile) {
                        g_free(srcfile);
-                       g_free(destfile);
                        break;
                }
 
index d332ab8..61aa884 100644 (file)
@@ -276,6 +276,7 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        gchar buf[BUFFSIZE];
        gushort port;
        gchar *domain;
+       gchar *user = NULL;
        gchar *pass = NULL;
        GSList *cur;
        gint size;
@@ -298,15 +299,30 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        domain = ac_prefs->set_domain ? ac_prefs->domain : NULL;
 
        if (ac_prefs->use_smtp_auth) {
-               if (ac_prefs->passwd)
-                       pass = ac_prefs->passwd;
-               else if (ac_prefs->tmp_pass)
-                       pass = ac_prefs->tmp_pass;
-               else {
-                       pass = send_query_password(ac_prefs->smtp_server,
-                                                  ac_prefs->userid);
-                       if (!pass) pass = g_strdup("");
-                       ac_prefs->tmp_pass = pass;
+               if (ac_prefs->smtp_userid) {
+                       user = ac_prefs->smtp_userid;
+                       if(ac_prefs->smtp_passwd)
+                               pass = ac_prefs->smtp_passwd;
+                       else if (ac_prefs->tmp_pass)
+                               pass = ac_prefs->tmp_pass;
+                       else {
+                               pass = send_query_password(ac_prefs->smtp_server,
+                                                          ac_prefs->smtp_userid);
+                               if (!pass) pass = g_strdup("");
+                               ac_prefs->tmp_pass = pass;
+                       }
+               } else {
+                       user = ac_prefs->userid;
+                       if (ac_prefs->passwd) {
+                               pass = ac_prefs->passwd;
+                       } else if (ac_prefs->tmp_pass)
+                               pass = ac_prefs->tmp_pass;
+                       else {
+                               pass = send_query_password(ac_prefs->smtp_server,
+                                                          ac_prefs->userid);
+                               if (!pass) pass = g_strdup("");
+                               ac_prefs->tmp_pass = pass;
+                       }
                }
        }
 
@@ -342,7 +358,7 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        GTK_EVENTS_FLUSH();
 
        SEND_EXIT_IF_NOTOK
-               (smtp_from(smtp_sock, ac_prefs->address, ac_prefs->userid,
+               (smtp_from(smtp_sock, ac_prefs->address, user,
                           pass, ac_prefs->use_smtp_auth),
                 "sending MAIL FROM");
 
index 075f7b6..6ec7051 100644 (file)
--- a/src/ssl.c
+++ b/src/ssl.c
@@ -36,110 +36,109 @@ static SSL_CTX *ssl_ctx_TLSv1;
 
 void ssl_init(void)
 {
-    SSL_library_init();
-    SSL_load_error_strings();
-
-    ssl_ctx_SSLv23 = SSL_CTX_new(SSLv23_client_method());
-    if (ssl_ctx_SSLv23 == NULL) {
-       debug_print(_("SSLv23 not available\n"));
-    } else {
-       debug_print(_("SSLv23 available\n"));
-    }
-
-    ssl_ctx_TLSv1 = SSL_CTX_new(TLSv1_client_method());
-    if (ssl_ctx_TLSv1 == NULL) {
-       debug_print(_("TLSv1 not available\n"));
-    } else {
-       debug_print(_("TLSv1 available\n"));
-    }
+       SSL_library_init();
+       SSL_load_error_strings();
+
+       ssl_ctx_SSLv23 = SSL_CTX_new(SSLv23_client_method());
+       if (ssl_ctx_SSLv23 == NULL) {
+               debug_print(_("SSLv23 not available\n"));
+       } else {
+               debug_print(_("SSLv23 available\n"));
+       }
+
+       ssl_ctx_TLSv1 = SSL_CTX_new(TLSv1_client_method());
+        if (ssl_ctx_TLSv1 == NULL) {
+               debug_print(_("TLSv1 not available\n"));
+       } else {
+               debug_print(_("TLSv1 available\n"));
+       }
 }
 
 void ssl_done(void)
 {
-    if (ssl_ctx_SSLv23) {
-       SSL_CTX_free(ssl_ctx_SSLv23);
-    }
+       if (ssl_ctx_SSLv23) {
+               SSL_CTX_free(ssl_ctx_SSLv23);
+       }
 
-    if (ssl_ctx_TLSv1) {
-       SSL_CTX_free(ssl_ctx_TLSv1);
-    }
+       if (ssl_ctx_TLSv1) {
+               SSL_CTX_free(ssl_ctx_TLSv1);
+       }
 }
 
 gboolean ssl_init_socket(SockInfo *sockinfo)
 {
-    return ssl_init_socket_with_method(sockinfo, SSL_METHOD_SSLv23);
+       return ssl_init_socket_with_method(sockinfo, SSL_METHOD_SSLv23);
 }
 
 gboolean ssl_init_socket_with_method(SockInfo *sockinfo, SSLMethod method)
 {
-    X509 *server_cert;
-    gint ret;
+       X509 *server_cert;
+       gint ret;
+
+       switch (method) {
+               case SSL_METHOD_SSLv23:
+                       if (!ssl_ctx_SSLv23) {
+                               log_warning(_("SSL method not available\n"));
+                               return FALSE;
+                       }
+                       sockinfo->ssl = SSL_new(ssl_ctx_SSLv23);
+                       break;
+               case SSL_METHOD_TLSv1:
+                       if (!ssl_ctx_TLSv1) {
+                               log_warning(_("SSL method not available\n"));
+                               return FALSE;
+                       }
+                       sockinfo->ssl = SSL_new(ssl_ctx_TLSv1);
+                       break;
+               default:
+                       log_warning(_("Unknown SSL method *PROGRAM BUG*\n"));
+                       return FALSE;
+                       break;
+       }
 
-    switch (method) {
-       case SSL_METHOD_SSLv23:
-           if (!ssl_ctx_SSLv23) {
-               log_warning(_("SSL method not available\n"));
-               return FALSE;
-           }
-           sockinfo->ssl = SSL_new(ssl_ctx_SSLv23);
-           break;
-       case SSL_METHOD_TLSv1:
-           if (!ssl_ctx_TLSv1) {
-               log_warning(_("SSL method not available\n"));
+       if (sockinfo->ssl == NULL) {
+               log_warning(_("Error creating ssl context\n"));
                return FALSE;
-           }
-           sockinfo->ssl = SSL_new(ssl_ctx_TLSv1);
-           break;
-       default:
-           log_warning(_("Unknown SSL method *PROGRAM BUG*\n"));
-           return FALSE;
-           break;
-    }
+       }
 
-    if (sockinfo->ssl == NULL) {
-       log_warning(_("Error creating ssl context\n"));
-       return FALSE;
-    }
+       SSL_set_fd(sockinfo->ssl, sockinfo->sock);
+       if ((ret = SSL_connect(sockinfo->ssl)) == -1) {
+               log_warning(_("SSL connect failed (%s)\n"),
+                           ERR_error_string(ERR_get_error(), NULL));
+               return FALSE;
+       }
 
-    SSL_set_fd(sockinfo->ssl, sockinfo->sock);
-    if ((ret = SSL_connect(sockinfo->ssl)) == -1) {
-       log_warning(_("SSL connect failed (%s)\n"),
-                   ERR_error_string(ERR_get_error(), NULL));
-       return FALSE;
-    }
+       /* Get the cipher */
+       log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
 
-    /* Get the cipher */
+       /* Get server's certificate (note: beware of dynamic allocation) */
 
-    log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
+       if ((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
+               gchar *str;
 
-    /* Get server's certificate (note: beware of dynamic allocation) */
+               log_print(_("Server certificate:\n"));
 
-    if ((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
-       gchar *str;
+               if ((str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0)) != NULL) {
+                       log_print(_("  Subject: %s\n"), str);
+                       free(str);
+               }
 
-       log_print(_("Server certificate:\n"));
+               if ((str = X509_NAME_oneline(X509_get_issuer_name(server_cert), 0, 0)) != NULL) {
+                       log_print(_("  Issuer: %s\n"), str);
+                       free(str);
+               }
 
-       if ((str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0)) != NULL) {
-               log_print(_("  Subject: %s\n"), str);
-               free(str);
+               X509_free(server_cert);
        }
 
-       if ((str = X509_NAME_oneline(X509_get_issuer_name(server_cert), 0, 0)) != NULL) {
-               log_print(_("  Issuer: %s\n"), str);
-               free(str);
-       }
-
-       X509_free(server_cert);
-    }
-
-    return TRUE;
+       return TRUE;
 }
 
 void ssl_done_socket(SockInfo *sockinfo)
 {
-    if (sockinfo->ssl) {
-       SSL_free(sockinfo->ssl);
-    }
+       if (sockinfo->ssl) {
+               SSL_free(sockinfo->ssl);
+       }
 }
 
 #endif /* USE_SSL */
index 52ee704..5f14e25 100644 (file)
--- a/src/ssl.h
+++ b/src/ssl.h
@@ -36,8 +36,8 @@
 #include "socket.h"
 
 typedef enum {
-    SSL_METHOD_SSLv23,
-    SSL_METHOD_TLSv1
+       SSL_METHOD_SSLv23,
+       SSL_METHOD_TLSv1
 } SSLMethod;
 
 void ssl_init(void);