Improve some sieve-related translations
[claws.git] / src / plugins / fetchinfo / fetchinfo_plugin.c
blob39f2394424a0469c33ac395a3c0ba3675182b5dc
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 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.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 # include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
30 /* common */
31 #include "version.h"
32 #include "claws.h"
33 #include "plugin.h"
34 #include "utils.h"
35 #include "hooks.h"
36 #include "inc.h"
37 #include "prefs.h"
38 #include "prefs_gtk.h"
39 #include "fetchinfo_plugin.h"
40 /* add headers */
41 #include "pop.h"
42 #include "quoted-printable.h"
43 /* parse headers */
44 #include "procheader.h"
46 static gulong mail_receive_hook_id = HOOK_NONE;
48 static FetchinfoConfig config;
50 static PrefParam param[] = {
51 {"fetchinfo_enable", "FALSE", &config.fetchinfo_enable, P_BOOL, NULL, NULL, NULL},
52 {"fetchinfo_uidl", "TRUE", &config.fetchinfo_uidl, P_BOOL, NULL, NULL, NULL},
53 {"fetchinfo_account", "TRUE", &config.fetchinfo_account, P_BOOL, NULL, NULL, NULL},
54 {"fetchinfo_server", "TRUE", &config.fetchinfo_server, P_BOOL, NULL, NULL, NULL},
55 {"fetchinfo_userid", "TRUE", &config.fetchinfo_userid, P_BOOL, NULL, NULL, NULL},
56 {"fetchinfo_time", "TRUE", &config.fetchinfo_time, P_BOOL, NULL, NULL, NULL},
58 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
61 gchar *fetchinfo_add_header(gchar **data, const gchar *header,const gchar *value)
63 gchar *line;
64 gchar *qpline;
65 gchar *newdata;
67 line = g_strdup_printf("%s: %s", header, value);
68 qpline = g_malloc(strlen(line)*4);
69 qp_encode_line(qpline, line);
70 newdata = g_strconcat(*data, qpline, NULL);
71 g_free(line);
72 g_free(qpline);
73 g_free(*data);
74 *data = newdata;
75 return newdata;
78 static gboolean mail_receive_hook(gpointer source, gpointer data)
80 MailReceiveData *mail_receive_data = (MailReceiveData *) source;
81 Pop3Session *session;
82 gchar *newheaders;
83 gchar *newdata;
84 gchar date[RFC822_DATE_BUFFSIZE];
86 if (!config.fetchinfo_enable) {
87 return FALSE;
90 g_return_val_if_fail(
91 mail_receive_data
92 && mail_receive_data->session
93 && mail_receive_data->data,
94 FALSE );
96 session = mail_receive_data->session;
97 get_rfc822_date(date, sizeof(date));
98 newheaders = g_strdup("");
100 if (config.fetchinfo_uidl)
101 fetchinfo_add_header(&newheaders, "X-FETCH-UIDL",
102 session->msg[session->cur_msg].uidl);
103 if (config.fetchinfo_account)
104 fetchinfo_add_header(&newheaders, "X-FETCH-ACCOUNT",
105 session->ac_prefs->account_name);
106 if (config.fetchinfo_server)
107 fetchinfo_add_header(&newheaders, "X-FETCH-SERVER",
108 session->ac_prefs->recv_server);
109 if (config.fetchinfo_userid)
110 fetchinfo_add_header(&newheaders, "X-FETCH-USERID",
111 session->ac_prefs->userid);
112 if (config.fetchinfo_time)
113 fetchinfo_add_header(&newheaders, "X-FETCH-TIME",
114 date);
116 newdata = g_strconcat(newheaders, mail_receive_data->data, NULL);
117 g_free(newheaders);
118 g_free(mail_receive_data->data);
119 mail_receive_data->data = newdata;
120 mail_receive_data->data_len = strlen(newdata);
121 return FALSE;
124 FetchinfoConfig *fetchinfo_get_config(void)
126 return &config;
129 void fetchinfo_save_config(void)
131 PrefFile *pfile;
132 gchar *rcpath;
134 debug_print("Saving Fetchinfo Page\n");
136 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
137 pfile = prefs_write_open(rcpath);
138 g_free(rcpath);
139 if (!pfile || (prefs_set_block_label(pfile, "Fetchinfo") < 0))
140 return;
142 if (prefs_write_param(param, pfile->fp) < 0) {
143 /* i18n: Possible error message during plugin load */
144 g_warning("failed to write Fetchinfo configuration to file");
145 prefs_file_close_revert(pfile);
146 return;
148 if (fprintf(pfile->fp, "\n") < 0) {
149 FILE_OP_ERROR(rcpath, "fprintf");
150 prefs_file_close_revert(pfile);
151 } else
152 prefs_file_close(pfile);
155 gint plugin_init(gchar **error)
157 gchar *rcpath;
159 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
160 VERSION_NUMERIC, _("Fetchinfo"), error))
161 return -1;
163 mail_receive_hook_id = hooks_register_hook(MAIL_RECEIVE_HOOKLIST, mail_receive_hook, NULL);
164 if (mail_receive_hook_id == HOOK_NONE) {
165 /* TRANSLATORS: Possible error message during plugin load */
166 *error = g_strdup(_("Failed to register mail receive hook"));
167 return -1;
170 prefs_set_default(param);
171 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
172 prefs_read_config(param, "Fetchinfo", rcpath, NULL);
173 g_free(rcpath);
175 fetchinfo_gtk_init();
177 debug_print("Fetchinfo plugin loaded\n");
179 return 0;
182 gboolean plugin_done(void)
184 hooks_unregister_hook(MAIL_RECEIVE_HOOKLIST, mail_receive_hook_id);
185 fetchinfo_gtk_done();
187 debug_print("Fetchinfo plugin unloaded\n");
188 return TRUE;
191 const gchar *plugin_name(void)
193 return _("Fetchinfo");
196 const gchar *plugin_desc(void)
198 /* TRANSLATORS: Description seen in plugins dialog.
199 * Translation of "Plugins" part of preferences path should to be
200 * the same as translation of "Plugins" string in Claws Mail message
201 * catalog. */
202 return _("This plugin modifies the downloaded messages. "
203 "It inserts headers containing some download "
204 "information: UIDL, Claws Mail account name, "
205 "POP server, user ID and retrieval time.\n"
206 "\n"
207 "Options can be found in /Configuration/Preferences/Plugins/Fetchinfo");
210 const gchar *plugin_type(void)
212 return "GTK3";
215 const gchar *plugin_licence(void)
217 return "GPL3+";
220 const gchar *plugin_version(void)
222 return VERSION;
225 struct PluginFeature *plugin_provides(void)
227 static struct PluginFeature features[] =
228 /* TRANSLATORS: Description of functionality added by this plugin */
229 { {PLUGIN_UTILITY, N_("Mail marking")},
230 {PLUGIN_NOTHING, NULL}};
231 return features;