Make SpamReport plugin use the password store.
[claws.git] / src / plugins / spam_report / spam_report.c
index 593a7c5c6c2a4720e2f848a649cef2ca82b5f807..e1987c53a2dee4ed2abf3cec3d941a5850e7c0ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net>
+ * Copyright (C) 1999-2014 Colin Leroy <colin@colino.net>
  * and the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <gdk/gdkx.h>
 #include "common/claws.h"
 #include "common/version.h"
 #include "main.h"
+#include "password.h"
 #include "plugin.h"
 #include "prefs_common.h"
 #include "utils.h"
@@ -44,7 +44,6 @@
 #include "plugin.h"
 #include "menu.h"
 #include "defs.h"
-#include "base64.h"
 #include "procheader.h"
 
 #ifdef USE_PTHREAD
@@ -64,13 +63,15 @@ static gboolean check_debian_listid(MsgInfo *msginfo);
 /* this interface struct is probably not enough for the various available 
  * reporting places/methods. It'll be extended as necessary. */
 
+#define SSFR_URL  "https://www.signal-spam.fr/api/signaler"
+#define SSFR_BODY "message=%claws_mail_body_b64%"
+
+#define DEBL_URL  "https://lists.debian.org/cgi-bin/nominate-for-review.pl?Quiet=on&msgid=%claws_mail_msgid%"
+
 ReportInterface spam_interfaces[] = {
-       { "Signal-Spam.fr", INTF_HTTP_AUTH, "https://www.signal-spam.fr/api/signaler",
-               "message=%claws_mail_body_b64%", NULL},
+       { "Signal-Spam.fr", INTF_HTTP_AUTH, SSFR_URL, SSFR_BODY, NULL},
        { "Spamcop.net", INTF_MAIL, NULL, NULL, NULL},
-       { "Debian Lists", INTF_HTTP_GET, 
-               "http://lists.debian.org/cgi-bin/nominate-for-review.pl?Quiet=on&msgid=%claws_mail_msgid%",
-               NULL, check_debian_listid},
+       { "Debian Lists", INTF_HTTP_GET, DEBL_URL, NULL, check_debian_listid},
        { NULL, INTF_NULL, NULL, NULL, NULL}
 };
 
@@ -194,7 +195,6 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
        gchar *reqbody = NULL, *tmp = NULL, *auth = NULL, *b64 = NULL, *geturl = NULL;
        size_t len_contents;
        CURL *curl;
-       CURLcode res;
        long response;
        struct CurlReadWrite chunk;
 
@@ -213,8 +213,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
        debug_print("reporting via %s\n", intf->name);
        tmp = spamreport_strreplace(intf->body, "%claws_mail_body%", contents);
        len_contents = strlen(contents);
-       b64 = g_malloc0(B64LEN(len_contents) + 1);
-       base64_encode(b64, contents, len_contents);
+       b64 = g_base64_encode(contents, len_contents);
        reqbody = spamreport_strreplace(tmp, "%claws_mail_body_b64%", b64);
        geturl = spamreport_strreplace(intf->url, "%claws_mail_msgid%", msginfo->msgid);
        g_free(b64);
@@ -223,7 +222,12 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
        switch(intf->type) {
        case INTF_HTTP_AUTH:
                if (spamreport_prefs.user[id] && *(spamreport_prefs.user[id])) {
-                       auth = g_strdup_printf("%s:%s", spamreport_prefs.user[id], spamreport_prefs.pass[id]);
+                       gchar *pass = spamreport_passwd_get(spam_interfaces[id].name);
+                       auth = g_strdup_printf("%s:%s", spamreport_prefs.user[id], (pass != NULL ? pass : ""));
+                       if (pass != NULL) {
+                               memset(pass, 0, strlen(pass));
+                       }
+                       g_free(pass);
 
                        curl = curl_easy_init();
                        curl_easy_setopt(curl, CURLOPT_URL, intf->url);
@@ -232,7 +236,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
                        curl_easy_setopt(curl, CURLOPT_TIMEOUT, prefs_common_get_prefs()->io_timeout_secs);
                        curl_easy_setopt(curl, CURLOPT_USERAGENT,
                                SPAM_REPORT_USERAGENT "(" PLUGINS_URI ")");
-                       res = curl_easy_perform(curl);
+                       curl_easy_perform(curl);
                        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
                        curl_easy_cleanup(curl);
                        spamreport_http_response_log(intf->url, response);
@@ -254,7 +258,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
                                SPAM_REPORT_USERAGENT "(" PLUGINS_URI ")");
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writefunction_cb);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
-               res = curl_easy_perform(curl);
+               curl_easy_perform(curl);
                curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
                curl_easy_cleanup(curl);
                spamreport_http_response_log(geturl, response);
@@ -269,7 +273,7 @@ static void report_spam(gint id, ReportInterface *intf, MsgInfo *msginfo, gchar
                }
                break;
        default:
-               g_warning("Unknown method\n");
+               g_warning("Unknown method");
        }
        g_free(reqbody);
        g_free(geturl);
@@ -337,14 +341,13 @@ gint plugin_init(gchar **error)
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
 
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(3,7,3,13),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(3,13,2,39),
                                VERSION_NUMERIC, _("SpamReport"), error))
                return -1;
 
        spamreport_prefs_init();
-#ifdef HAVE_LIBCURL
+
        curl_global_init(CURL_GLOBAL_DEFAULT);
-#endif
 
        gtk_action_group_add_actions(mainwin->action_group, spamreport_main_menu,
                        1, (gpointer)mainwin);
@@ -360,20 +363,18 @@ gint plugin_init(gchar **error)
 gboolean plugin_done(void)
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
-       SummaryView *summaryview = NULL;
 
        if (mainwin == NULL)
                return TRUE;
 
-       summaryview = mainwin->summaryview;
        MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "Message/ReportSpam", main_menu_id);
        main_menu_id = 0;
 
        MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "Message/ReportSpam", context_menu_id);
        context_menu_id = 0;
-#ifdef HAVE_LIBCURL
+
        spamreport_prefs_done();
-#endif
+
        return TRUE;
 }