2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # include "claws-features.h"
28 #include <glib/gi18n.h>
38 #include "prefs_gtk.h"
39 #include "fetchinfo_plugin.h"
42 #include "quoted-printable.h"
44 #include "procheader.h"
47 static guint mail_receive_hook_id;
49 static FetchinfoConfig config;
51 static PrefParam param[] = {
52 {"fetchinfo_enable", "FALSE", &config.fetchinfo_enable,
53 P_BOOL, NULL, NULL, NULL},
54 {"fetchinfo_uidl", "TRUE", &config.fetchinfo_uidl,
55 P_BOOL, NULL, NULL, NULL},
56 {"fetchinfo_account", "TRUE", &config.fetchinfo_account,
57 P_BOOL, NULL, NULL, NULL},
58 {"fetchinfo_server", "TRUE", &config.fetchinfo_server,
59 P_BOOL, NULL, NULL, NULL},
60 {"fetchinfo_userid", "TRUE", &config.fetchinfo_userid,
61 P_BOOL, NULL, NULL, NULL},
62 {"fetchinfo_time", "TRUE", &config.fetchinfo_time,
63 P_BOOL, NULL, NULL, NULL},
65 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
68 gchar *fetchinfo_add_header(gchar **data, const gchar *header,const gchar *value)
74 line = g_strdup_printf("%s: %s", header, value);
75 qpline = g_malloc(strlen(line)*4);
76 qp_encode_line(qpline, line);
77 newdata = g_strconcat(*data, qpline, NULL);
85 static gboolean mail_receive_hook(gpointer source, gpointer data)
87 MailReceiveData *mail_receive_data = (MailReceiveData *) source;
91 gchar date[PREFSBUFSIZE];
93 if (!config.fetchinfo_enable) {
99 && mail_receive_data->session
100 && mail_receive_data->data,
103 session = mail_receive_data->session;
104 get_rfc822_date(date, PREFSBUFSIZE);
105 newheaders = g_strdup("");
107 if (config.fetchinfo_uidl)
108 fetchinfo_add_header(&newheaders, "X-FETCH-UIDL",
109 session->msg[session->cur_msg].uidl);
110 if (config.fetchinfo_account)
111 fetchinfo_add_header(&newheaders, "X-FETCH-ACCOUNT",
112 session->ac_prefs->account_name);
113 if (config.fetchinfo_server)
114 fetchinfo_add_header(&newheaders, "X-FETCH-SERVER",
115 session->ac_prefs->recv_server);
116 if (config.fetchinfo_userid)
117 fetchinfo_add_header(&newheaders, "X-FETCH-USERID",
118 session->ac_prefs->userid);
119 if (config.fetchinfo_time)
120 fetchinfo_add_header(&newheaders, "X-FETCH-TIME",
123 newdata = g_strconcat(newheaders, mail_receive_data->data, NULL);
125 g_free(mail_receive_data->data);
126 mail_receive_data->data = newdata;
127 mail_receive_data->data_len = strlen(newdata);
131 FetchinfoConfig *fetchinfo_get_config(void)
136 void fetchinfo_save_config(void)
141 debug_print("Saving Fetchinfo Page\n");
143 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
144 pfile = prefs_write_open(rcpath);
146 if (!pfile || (prefs_set_block_label(pfile, "Fetchinfo") < 0))
149 if (prefs_write_param(param, pfile->fp) < 0) {
150 /* i18n: Possible error message during plugin load */
151 g_warning(_("failed to write Fetchinfo configuration to file\n"));
152 prefs_file_close_revert(pfile);
155 if (fprintf(pfile->fp, "\n") < 0) {
156 FILE_OP_ERROR(rcpath, "fprintf");
157 prefs_file_close_revert(pfile);
159 prefs_file_close(pfile);
162 gint plugin_init(gchar **error)
166 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
167 VERSION_NUMERIC, _("Fetchinfo"), error))
170 mail_receive_hook_id = hooks_register_hook(MAIL_RECEIVE_HOOKLIST, mail_receive_hook, NULL);
171 if (mail_receive_hook_id == (guint)-1) {
172 /* i18n: Possible error message during plugin load */
173 *error = g_strdup(_("Failed to register mail receive hook"));
177 prefs_set_default(param);
178 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
179 prefs_read_config(param, "Fetchinfo", rcpath, NULL);
182 fetchinfo_gtk_init();
184 debug_print("Fetchinfo plugin loaded\n");
189 gboolean plugin_done(void)
191 hooks_unregister_hook(MAIL_RECEIVE_HOOKLIST, mail_receive_hook_id);
192 fetchinfo_gtk_done();
194 debug_print("Fetchinfo plugin unloaded\n");
198 const gchar *plugin_name(void)
200 return _("Fetchinfo");
203 const gchar *plugin_desc(void)
205 /* i18n: Description seen in plugins dialog.
206 * Translation of "Plugins" part of preferences path should to be
207 * the same as translation of "Plugins" string in Claws Mail message
209 return _("This plugin modifies the downloaded messages. "
210 "It inserts headers containing some download "
211 "information: UIDL, Claws Mail account name, "
212 "POP server, user ID and retrieval time.\n"
214 "Options can be found in /Configuration/Preferences/Plugins/Fetchinfo");
217 const gchar *plugin_type(void)
222 const gchar *plugin_licence(void)
227 const gchar *plugin_version(void)
232 struct PluginFeature *plugin_provides(void)
234 static struct PluginFeature features[] =
235 /* i18n: Description of functionality added by this plugin */
236 { {PLUGIN_UTILITY, N_("Mail marking")},
237 {PLUGIN_NOTHING, NULL}};