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-2012 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>
42 static FILE *NewLog = NULL;
43 static char *LogName = NULL;
44 static int truncLog = 1;
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);
58 tof = msginfo->folder;
59 (void)fprintf (NewLog, "---\n"
69 defstr (msginfo->date),
70 defstr (msginfo->subject),
71 defstr (msginfo->from),
74 (intmax_t) msginfo->size,
75 defstr (procmsg_get_message_file_path (msginfo)),
77 tof ? defstr (tof->name) : "(null)");
82 gboolean plugin_done (void)
85 (void)fclose (NewLog);
89 hooks_unregister_hook (MAIL_POSTFILTERING_HOOKLIST, hook_id);
91 printf (_("Newmail plugin unloaded\n"));
95 gint plugin_init (gchar **error)
97 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
98 VERSION_NUMERIC, _("NewMail"), error))
101 hook_id = hooks_register_hook (MAIL_POSTFILTERING_HOOKLIST, newmail_hook, NULL);
103 *error = g_strdup (_("Failed to register newmail hook"));
108 auto char *mode = truncLog ? "w" : "a";
112 (void)snprintf (name, 256, "%s/Mail/NewLog", getenv ("HOME"));
114 if (l > 255 || !(LogName = (char *)malloc (l + 1))) {
115 *error = g_strdup (_("Cannot load plugin NewMail\n"
116 "$HOME is too long\n"));
120 (void)strcpy (LogName, name);
122 if (!(NewLog = fopen (LogName, mode))) {
123 *error = g_strdup (sys_errlist[errno]);
127 setbuf (NewLog, NULL);
130 printf (_("Newmail plugin loaded\n"
131 "Message header summaries written to %s\n"), LogName);
135 const gchar *plugin_name (void)
140 const gchar *plugin_desc (void)
142 return _("This Plugin writes a header summary to a log file for each "
143 "mail received after sorting.\n\n"
144 "Default is ~/Mail/NewLog");
147 const gchar *plugin_type (void)
152 const gchar *plugin_licence (void)
155 } /* plugin_licence */
157 const gchar *plugin_version (void)
160 } /* plugin_version */
162 struct PluginFeature *plugin_provides(void)
164 static struct PluginFeature features[] =
165 { {PLUGIN_NOTIFIER, N_("Log file")},
166 {PLUGIN_NOTHING, NULL}};