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.
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"
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
)
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
);
78 static gboolean
mail_receive_hook(gpointer source
, gpointer data
)
80 MailReceiveData
*mail_receive_data
= (MailReceiveData
*) source
;
84 gchar date
[RFC822_DATE_BUFFSIZE
];
86 if (!config
.fetchinfo_enable
) {
92 && mail_receive_data
->session
93 && mail_receive_data
->data
,
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",
116 newdata
= g_strconcat(newheaders
, mail_receive_data
->data
, NULL
);
118 g_free(mail_receive_data
->data
);
119 mail_receive_data
->data
= newdata
;
120 mail_receive_data
->data_len
= strlen(newdata
);
124 FetchinfoConfig
*fetchinfo_get_config(void)
129 void fetchinfo_save_config(void)
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
);
139 if (!pfile
|| (prefs_set_block_label(pfile
, "Fetchinfo") < 0))
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
);
148 if (fprintf(pfile
->fp
, "\n") < 0) {
149 FILE_OP_ERROR(rcpath
, "fprintf");
150 prefs_file_close_revert(pfile
);
152 prefs_file_close(pfile
);
155 gint
plugin_init(gchar
**error
)
159 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
160 VERSION_NUMERIC
, _("Fetchinfo"), error
))
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"));
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
);
175 fetchinfo_gtk_init();
177 debug_print("Fetchinfo plugin loaded\n");
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");
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
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"
207 "Options can be found in /Configuration/Preferences/Plugins/Fetchinfo");
210 const gchar
*plugin_type(void)
215 const gchar
*plugin_licence(void)
220 const gchar
*plugin_version(void)
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
}};