2 * newmail - A plugin for Claws Mail
4 * Copyright (C) 2005-2005 H.Merijn Brand and the Claws Mail Team
6 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
7 * Copyright (C) 1999-2013 the Claws Mail Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <glib/gi18n.h>
40 #define LOG_NAME "NewLog"
41 #define DEFAULT_DIR "Mail"
45 static FILE *NewLog = NULL;
46 static char *LogName = NULL;
47 static int truncLog = 1;
48 static char *pluginDesc = NULL;
50 static gchar *defstr (gchar *s)
52 return s ? s : "(null)";
55 gboolean newmail_hook (gpointer source, gpointer data)
57 auto MsgInfo *msginfo = (MsgInfo *)source;
60 if (!msginfo) return FALSE;
61 if (!NewLog) return FALSE;
63 tof = msginfo->folder;
64 (void)fprintf (NewLog, "---\n"
74 defstr (msginfo->date),
75 defstr (msginfo->subject),
76 defstr (msginfo->from),
79 (intmax_t) msginfo->size,
80 defstr (procmsg_get_message_file_path (msginfo)),
82 tof ? defstr (tof->name) : "(null)");
87 gboolean plugin_done (void)
90 (void)fclose (NewLog);
101 hooks_unregister_hook (MAIL_POSTFILTERING_HOOKLIST, hook_id);
103 debug_print ("Newmail plugin unloaded\n");
107 gint plugin_init (gchar **error)
109 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
110 VERSION_NUMERIC, _("NewMail"), error))
113 hook_id = hooks_register_hook (MAIL_POSTFILTERING_HOOKLIST, newmail_hook, NULL);
115 *error = g_strdup (_("Failed to register newmail hook"));
120 auto char *mode = truncLog ? "w" : "a";
122 LogName = g_strconcat(getenv ("HOME"), G_DIR_SEPARATOR_S, DEFAULT_DIR,
123 G_DIR_SEPARATOR_S, LOG_NAME, NULL);
125 if (!(NewLog = fopen (LogName, mode))) {
126 debug_print ("Failed to open default log %s\n", LogName);
127 /* try fallback location */
129 LogName = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, LOG_NAME, NULL);
130 if (!(NewLog = fopen (LogName, mode))) {
131 debug_print ("Failed to open fallback log %s\n", LogName);
132 *error = g_strdup_printf(_("Could not open log file %s: %s\n"),
133 LogName, sys_errlist[errno]);
138 setbuf (NewLog, NULL);
141 debug_print ("Newmail plugin loaded\n"
142 "Message header summaries written to %s\n", LogName);
143 if (pluginDesc == NULL)
144 pluginDesc = g_strdup_printf(
145 _("This plugin writes a header summary to a log file for each "
146 "mail received after sorting.\n\n"
147 "Default is ~/Mail/NewLog\n\nCurrent log is %s"), LogName);
151 const gchar *plugin_name (void)
156 const gchar *plugin_desc (void)
161 const gchar *plugin_type (void)
166 const gchar *plugin_licence (void)
169 } /* plugin_licence */
171 const gchar *plugin_version (void)
174 } /* plugin_version */
176 struct PluginFeature *plugin_provides(void)
178 static struct PluginFeature features[] =
179 { {PLUGIN_NOTIFIER, N_("Log file")},
180 {PLUGIN_NOTHING, NULL}};