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/>.
22 #include <glib/gi18n.h>
35 #define LOG_NAME "NewLog"
36 #define DEFAULT_DIR "Mail"
41 static FILE *NewLog = NULL;
42 static char *LogName = NULL;
43 static int truncLog = 1;
44 static char *pluginDesc = NULL;
46 static gchar *defstr (gchar *s)
48 return s ? s : "(null)";
51 gboolean newmail_hook (gpointer source, gpointer data)
53 auto MsgInfo *msginfo = (MsgInfo *)source;
56 if (!msginfo) return FALSE;
57 if (!NewLog) return FALSE;
59 tof = msginfo->folder;
60 (void)fprintf (NewLog, "---\n"
70 defstr (msginfo->date),
71 defstr (msginfo->subject),
72 defstr (msginfo->from),
75 (intmax_t) msginfo->size,
76 defstr (procmsg_get_message_file_path (msginfo)),
78 tof ? defstr (tof->name) : "(null)");
83 gboolean plugin_done (void)
86 (void)fclose (NewLog);
97 hooks_unregister_hook (MAIL_POSTFILTERING_HOOKLIST, hook_id);
99 debug_print ("Newmail plugin unloaded\n");
103 gint plugin_init (gchar **error)
105 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
106 VERSION_NUMERIC, _("NewMail"), error))
109 hook_id = hooks_register_hook (MAIL_POSTFILTERING_HOOKLIST, newmail_hook, NULL);
111 *error = g_strdup (_("Failed to register newmail hook"));
116 auto char *mode = truncLog ? "w" : "a";
118 LogName = g_strconcat(g_getenv ("HOME"), G_DIR_SEPARATOR_S, DEFAULT_DIR,
119 G_DIR_SEPARATOR_S, LOG_NAME, NULL);
121 if (!(NewLog = fopen (LogName, mode))) {
122 debug_print ("Failed to open default log %s\n", LogName);
123 /* try fallback location */
125 LogName = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, LOG_NAME, NULL);
126 if (!(NewLog = fopen (LogName, mode))) {
127 debug_print ("Failed to open fallback log %s\n", LogName);
128 *error = g_strdup_printf(_("Could not open log file %s: %s\n"),
129 LogName, g_strerror(errno));
134 setbuf (NewLog, NULL);
137 debug_print ("Newmail plugin loaded\n"
138 "Message header summaries written to %s\n", LogName);
139 if (pluginDesc == NULL)
140 pluginDesc = g_strdup_printf(
141 _("This plugin writes a header summary to a log file for each "
142 "mail received after sorting.\n\n"
143 "Default is ~/Mail/NewLog\n\nCurrent log is %s"), LogName);
147 const gchar *plugin_name (void)
152 const gchar *plugin_desc (void)
157 const gchar *plugin_type (void)
162 const gchar *plugin_licence (void)
165 } /* plugin_licence */
167 const gchar *plugin_version (void)
170 } /* plugin_version */
172 struct PluginFeature *plugin_provides(void)
174 static struct PluginFeature features[] =
175 { {PLUGIN_NOTIFIER, N_("Log file")},
176 {PLUGIN_NOTHING, NULL}};