added SSL support for POP using OpenSSL
[claws.git] / src / main.c
index 549da44d723712a5728278655e778b0f5c657e8c..61f4419a77098556bec331bc8eb6b1eecfe1f86b 100644 (file)
@@ -57,6 +57,8 @@
 #include "prefs_common.h"
 #include "prefs_filter.h"
 #include "prefs_account.h"
+#include "scoring.h"
+#include "prefs_display_header.h"
 #include "account.h"
 #include "procmsg.h"
 #include "inc.h"
 #include "utils.h"
 #include "gtkutils.h"
 
+#if USE_GPGME
+#  include "rfc2015.h"
+#endif
+
 gchar *prog_version;
 gchar *startup_dir;
 gboolean debug_mode = FALSE;
@@ -77,6 +83,10 @@ gboolean debug_mode = FALSE;
 static gint lock_socket = -1;
 static gint lock_socket_tag = 0;
 
+#if USE_SSL
+SSL_CTX *ssl_ctx;
+#endif
+
 static struct Cmd {
        gboolean receive;
        gboolean receive_all;
@@ -133,6 +143,8 @@ int main(int argc, char *argv[])
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
+       parse_cmd_opt(argc, argv);
+
        gtk_set_locale();
        gtk_init(&argc, &argv);
 
@@ -148,6 +160,8 @@ int main(int argc, char *argv[])
        gtk_widget_push_colormap(gdk_imlib_get_colormap());
 #endif
 
+       srandom((gint)time(NULL));
+
        /* parse gtkrc files */
        userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc",
                             NULL);
@@ -170,8 +184,6 @@ int main(int argc, char *argv[])
        prog_version = PROG_VERSION;
        startup_dir = g_get_current_dir();
 
-       parse_cmd_opt(argc, argv);
-
        CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
 
        /* check and create unix domain socket */
@@ -188,6 +200,13 @@ int main(int argc, char *argv[])
        MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
 
+       if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
+               if (rename(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log",
+                          RC_DIR G_DIR_SEPARATOR_S "sylpheed.log.bak") < 0)
+                       FILE_OP_ERROR("sylpheed.log", "rename");
+       }
+       set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
+
        if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "assortrc") &&
            !is_file_exist(RC_DIR G_DIR_SEPARATOR_S "filterrc")) {
                if (rename(RC_DIR G_DIR_SEPARATOR_S "assortrc",
@@ -196,15 +215,7 @@ int main(int argc, char *argv[])
                                      "rename");
        }
 
-       srandom((gint)time(NULL));
-
        prefs_common_read_config();
-       prefs_common_save_config();
-       prefs_filter_read_config();
-       prefs_filter_write_config();
-       prefs_display_headers_read_config();
-       prefs_display_headers_write_config();
-       prefs_scoring_read_config();
 
 #if USE_GPGME
        if (gpgme_check_engine()) {  /* Also does some gpgme init */
@@ -212,20 +223,42 @@ int main(int argc, char *argv[])
                debug_print("gpgme_engine_version:\n%s\n",
                            gpgme_get_engine_info());
 
-               if (prefs_common.gpgme_warning) {
-                       AlertValue v = alertpanel_message_with_disable
+               if (prefs_common.gpg_warning) {
+                       AlertValue val;
+
+                       val = alertpanel_message_with_disable
                                (_("Warning"),
                                 _("GnuPG is not installed properly.\n"
                                   "OpenPGP support disabled."));
-                       if (v & G_ALERTDISABLE) {
-                               prefs_common.gpgme_warning = FALSE;
-                               prefs_common_save_config();
-                       }
+                       if (val & G_ALERTDISABLE)
+                               prefs_common.gpg_warning = FALSE;
                }
        }
        gpgme_register_idle(idle_function_for_gpgme);
 #endif
 
+#if USE_SSL
+       {
+               SSL_METHOD *meth;
+               
+               SSLeay_add_ssl_algorithms();
+               meth = SSLv2_client_method();
+               SSL_load_error_strings();
+               ssl_ctx = SSL_CTX_new(meth);
+               if(ssl_ctx == NULL) {
+                       debug_print(_("SSL disabled\n"));
+               } else {
+                       debug_print(_("SSL loaded: \n"));
+               }
+       }
+#endif
+
+       prefs_common_save_config();
+       prefs_filter_read_config();
+       prefs_filter_write_config();
+       prefs_display_header_read_config();
+       prefs_display_header_write_config();
+
        gtkut_widget_init();
 
        mainwin = main_window_create
@@ -245,9 +278,14 @@ int main(int argc, char *argv[])
        account_set_missing_folder();
        folderview_set(folderview);
 
-       if (cmd.receive_all)
+       prefs_filtering_read_config();
+       prefs_scoring_read_config();
+
+       inc_autocheck_timer_init(mainwin);
+
+       if (cmd.receive_all || prefs_common.chk_on_startup)
                inc_all_account_mail(mainwin);
-       else if (prefs_common.chk_on_startup || cmd.receive)
+       else if (cmd.receive)
                inc_mail(mainwin);
        else
                gtk_widget_grab_focus(folderview->ctree);
@@ -260,6 +298,12 @@ int main(int argc, char *argv[])
 
        gtk_main();
 
+#if USE_SSL
+       if(ssl_ctx) {
+               SSL_CTX_free(ssl_ctx);
+       }
+#endif
+
        return 0;
 }
 
@@ -290,7 +334,8 @@ static void parse_cmd_opt(int argc, char *argv[])
                        puts("Sylpheed version " VERSION);
                        exit(0);
                } else if (!strncmp(argv[i], "--help", 6)) {
-                       g_print(_("Usage: %s [OPTION]...\n"), g_get_prgname());
+                       g_print(_("Usage: %s [OPTION]...\n"),
+                               g_basename(argv[0]));
 
                        puts(_("  --compose [address]    open composition window"));
                        puts(_("  --receive              receive new messages"));
@@ -357,6 +402,8 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        /* delete temporary files */
        remove_all_files(get_mime_tmp_dir());
 
+       close_log_file();
+
        /* delete unix domain socket */
        gdk_input_remove(lock_socket_tag);
        fd_close(lock_socket);
@@ -433,7 +480,7 @@ static void lock_socket_input_cb(gpointer data,
        gchar buf[BUFFSIZE];
 
        sock = fd_accept(source);
-       fd_read(sock, buf, sizeof(buf));
+       fd_gets(sock, buf, sizeof(buf));
        fd_close(sock);
 
        if (!strncmp(buf, "popup", 5)){
@@ -463,4 +510,3 @@ static void open_compose_new_with_recipient(const gchar *address)
        else
                compose_new(NULL);
 }
-