2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2005-2015 H.Merijn Brand and the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <glib/gi18n.h>
35 #include "file-utils.h"
37 #define LOG_NAME "NewLog"
38 #define DEFAULT_DIR "Mail"
40 static gulong hook_id = HOOK_NONE;
42 static FILE *NewLog = NULL;
43 static char *LogName = NULL;
44 static int truncLog = 1;
45 static char *pluginDesc = NULL;
47 static gchar *defstr (gchar *s)
49 return s ? s : "(null)";
52 gboolean newmail_hook (gpointer source, gpointer data)
54 auto MsgInfo *msginfo = (MsgInfo *)source;
57 if (!msginfo) return FALSE;
58 if (!NewLog) return FALSE;
60 tof = msginfo->folder;
61 (void)fprintf (NewLog, "---\n"
71 defstr (msginfo->date),
72 defstr (msginfo->subject),
73 defstr (msginfo->from),
76 (intmax_t) msginfo->size,
77 defstr (procmsg_get_message_file_path (msginfo)),
79 tof ? defstr (tof->name) : "(null)");
84 gboolean plugin_done (void)
87 (void)claws_fclose (NewLog);
98 hooks_unregister_hook (MAIL_POSTFILTERING_HOOKLIST, hook_id);
100 debug_print ("Newmail plugin unloaded\n");
104 gint plugin_init (gchar **error)
106 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
107 VERSION_NUMERIC, _("NewMail"), error))
110 hook_id = hooks_register_hook (MAIL_POSTFILTERING_HOOKLIST, newmail_hook, NULL);
111 if (hook_id == HOOK_NONE) {
112 *error = g_strdup (_("Failed to register newmail hook"));
117 auto char *mode = truncLog ? "w" : "a";
119 LogName = g_strconcat(g_getenv ("HOME"), G_DIR_SEPARATOR_S, DEFAULT_DIR,
120 G_DIR_SEPARATOR_S, LOG_NAME, NULL);
122 if (!(NewLog = claws_fopen (LogName, mode))) {
123 debug_print ("Failed to open default log %s\n", LogName);
124 /* try fallback location */
126 LogName = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, LOG_NAME, NULL);
127 if (!(NewLog = claws_fopen (LogName, mode))) {
128 debug_print ("Failed to open fallback log %s\n", LogName);
129 *error = g_strdup_printf(_("Could not open log file %s: %s\n"),
130 LogName, g_strerror(errno));
135 setbuf (NewLog, NULL);
138 debug_print ("Newmail plugin loaded\n"
139 "Message header summaries written to %s\n", LogName);
140 if (pluginDesc == NULL)
141 pluginDesc = g_strdup_printf(
142 _("This plugin writes a header summary to a log file for each "
143 "mail received after sorting.\n\n"
144 "Default is ~/Mail/NewLog\n\nCurrent log is %s"), LogName);
148 const gchar *plugin_name (void)
153 const gchar *plugin_desc (void)
158 const gchar *plugin_type (void)
163 const gchar *plugin_licence (void)
166 } /* plugin_licence */
168 const gchar *plugin_version (void)
171 } /* plugin_version */
173 struct PluginFeature *plugin_provides(void)
175 static struct PluginFeature features[] =
176 { {PLUGIN_NOTIFIER, N_("Log file")},
177 {PLUGIN_NOTHING, NULL}};