Statistics
| Revision:

root / libsylph / prefs_common.c @ 1864

History | View | Annotate | Download (19.7 kB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifdef HAVE_CONFIG_H
21
#  include "config.h"
22
#endif
23
24
#include "defs.h"
25
26
#include <glib.h>
27
#include <glib/gi18n.h>
28
#include <stdio.h>
29
#include <errno.h>
30
31
#include "prefs.h"
32
#include "prefs_common.h"
33
#include "filter.h"
34
#include "codeconv.h"
35
#include "utils.h"
36
37
PrefsCommon prefs_common;
38
39
static PrefParam param[] = {
40
        /* Receive */
41
        {"autochk_newmail", "FALSE", &prefs_common.autochk_newmail, P_BOOL},
42
        {"autochk_interval", "10", &prefs_common.autochk_itv, P_INT},
43
        {"check_on_startup", "FALSE", &prefs_common.chk_on_startup, P_BOOL},
44
        {"scan_all_after_inc", "FALSE", &prefs_common.scan_all_after_inc,
45
         P_BOOL},
46
        {"enable_newmsg_notify", "FALSE", &prefs_common.enable_newmsg_notify,
47
         P_BOOL},
48
        {"newmsg_notify_command", NULL, &prefs_common.newmsg_notify_cmd,
49
         P_STRING},
50
51
        {"inc_local", "FALSE", &prefs_common.inc_local, P_BOOL},
52
        {"filter_on_inc_local", "TRUE", &prefs_common.filter_on_inc, P_BOOL},
53
        {"spool_path", DEFAULT_SPOOL_PATH, &prefs_common.spool_path, P_STRING},
54
55
        /* Send */
56
        {"save_message", "TRUE", &prefs_common.savemsg, P_BOOL},
57
        {"filter_sent_message", "FALSE", &prefs_common.filter_sent, P_BOOL},
58
59
        {"encoding_method", "0", &prefs_common.encoding_method, P_ENUM},
60
        {"mime_filename_encoding_method", "0",
61
         &prefs_common.mime_fencoding_method, P_ENUM},
62
63
        {"allow_jisx0201_kana", "FALSE", &prefs_common.allow_jisx0201_kana,
64
         P_BOOL},
65
66
        /* Compose */
67
        {"auto_signature", "TRUE", &prefs_common.auto_sig, P_BOOL},
68
        {"signature_separator", "-- ", &prefs_common.sig_sep, P_STRING},
69
70
        {"auto_ext_editor", "FALSE", &prefs_common.auto_exteditor, P_BOOL},
71
72
        {"undo_level", "50", &prefs_common.undolevels, P_INT},
73
74
        {"linewrap_length", "72", &prefs_common.linewrap_len, P_INT},
75
        {"linewrap_quotation", "FALSE", &prefs_common.linewrap_quote, P_BOOL},
76
        {"linewrap_auto", "FALSE", &prefs_common.autowrap, P_BOOL},
77
78
        {"enable_autosave", "FALSE", &prefs_common.enable_autosave, P_BOOL},
79
        {"autosave_interval", "5", &prefs_common.autosave_itv, P_INT},
80
81
        {"reply_with_quote", "TRUE", &prefs_common.reply_with_quote, P_BOOL},
82
        {"reply_account_autoselect", "TRUE",
83
         &prefs_common.reply_account_autosel, P_BOOL},
84
        {"default_reply_list", "TRUE", &prefs_common.default_reply_list,
85
         P_BOOL},
86
        {"inherit_recipient_on_self_reply", "FALSE",
87
         &prefs_common.inherit_recipient_on_self_reply, P_BOOL},
88
89
        {"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL},
90
91
        /* Quote */
92
        {"reply_quote_mark", "> ", &prefs_common.quotemark, P_STRING},
93
        {"reply_quote_format", "On %d\\n%f wrote:\\n\\n%Q",
94
         &prefs_common.quotefmt, P_STRING},
95
96
        {"forward_quote_mark", "> ", &prefs_common.fw_quotemark, P_STRING},
97
        {"forward_quote_format",
98
         "\\n\\nBegin forwarded message:\\n\\n"
99
         "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
100
         "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M",
101
         &prefs_common.fw_quotefmt, P_STRING},
102
103
        /* Spelling */
104
        {"check_spell", "FALSE", &prefs_common.check_spell, P_BOOL},
105
        {"spell_lang", "en", &prefs_common.spell_lang, P_STRING},
106
107
        /* Display */
108
        {"message_font_name", DEFAULT_MESSAGE_FONT, &prefs_common.textfont,
109
         P_STRING},
110
111
        {"display_folder_unread_num", "TRUE",
112
         &prefs_common.display_folder_unread, P_BOOL},
113
        {"display_folder_num_columns", "FALSE",
114
         &prefs_common.display_folder_num_columns, P_BOOL},
115
116
        {"newsgroup_abbrev_len", "16", &prefs_common.ng_abbrev_len, P_INT},
117
118
        {"translate_header", "TRUE", &prefs_common.trans_hdr, P_BOOL},
119
120
        /* Display: Summary View */
121
        {"enable_swap_from", "FALSE", &prefs_common.swap_from, P_BOOL},
122
        {"date_format", "%y/%m/%d(%a) %H:%M", &prefs_common.date_format,
123
         P_STRING},
124
        {"expand_thread", "TRUE", &prefs_common.expand_thread, P_BOOL},
125
126
        {"enable_rules_hint", "TRUE", &prefs_common.enable_rules_hint, P_BOOL},
127
        {"bold_unread", "TRUE", &prefs_common.bold_unread, P_BOOL},
128
129
        {"persist_qsearch_filter", "TRUE", &prefs_common.persist_qsearch_filter,
130
         P_BOOL},
131
132
        {"toolbar_style", "4", &prefs_common.toolbar_style, P_ENUM},
133
        {"show_searchbar", "TRUE", &prefs_common.show_searchbar, P_BOOL},
134
        {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL},
135
136
        {"main_toolbar_setting", NULL, &prefs_common.main_toolbar_setting,
137
         P_STRING},
138
        {"compose_toolbar_setting", NULL,
139
         &prefs_common.compose_toolbar_setting, P_STRING},
140
141
        {"summary_col_show_mark", "TRUE",
142
         &prefs_common.summary_col_visible[S_COL_MARK], P_BOOL},
143
        {"summary_col_show_unread", "TRUE",
144
         &prefs_common.summary_col_visible[S_COL_UNREAD], P_BOOL},
145
        {"summary_col_show_mime", "TRUE",
146
         &prefs_common.summary_col_visible[S_COL_MIME], P_BOOL},
147
        {"summary_col_show_subject", "TRUE",
148
         &prefs_common.summary_col_visible[S_COL_SUBJECT], P_BOOL},
149
        {"summary_col_show_from", "TRUE",
150
         &prefs_common.summary_col_visible[S_COL_FROM], P_BOOL},
151
        {"summary_col_show_date", "TRUE",
152
         &prefs_common.summary_col_visible[S_COL_DATE], P_BOOL},
153
        {"summary_col_show_size", "TRUE",
154
         &prefs_common.summary_col_visible[S_COL_SIZE], P_BOOL},
155
        {"summary_col_show_number", "FALSE",
156
         &prefs_common.summary_col_visible[S_COL_NUMBER], P_BOOL},
157
158
        {"summary_col_pos_mark", "0",
159
          &prefs_common.summary_col_pos[S_COL_MARK], P_INT},
160
        {"summary_col_pos_unread", "1",
161
          &prefs_common.summary_col_pos[S_COL_UNREAD], P_INT},
162
        {"summary_col_pos_mime", "2",
163
          &prefs_common.summary_col_pos[S_COL_MIME], P_INT},
164
        {"summary_col_pos_subject", "3",
165
          &prefs_common.summary_col_pos[S_COL_SUBJECT], P_INT},
166
        {"summary_col_pos_from", "4",
167
          &prefs_common.summary_col_pos[S_COL_FROM], P_INT},
168
        {"summary_col_pos_date", "5",
169
          &prefs_common.summary_col_pos[S_COL_DATE], P_INT},
170
        {"summary_col_pos_size", "6",
171
          &prefs_common.summary_col_pos[S_COL_SIZE], P_INT},
172
        {"summary_col_pos_number", "7",
173
          &prefs_common.summary_col_pos[S_COL_NUMBER], P_INT},
174
175
        {"summary_col_size_mark", "10",
176
         &prefs_common.summary_col_size[S_COL_MARK], P_INT},
177
        {"summary_col_size_unread", "13",
178
         &prefs_common.summary_col_size[S_COL_UNREAD], P_INT},
179
        {"summary_col_size_mime", "10",
180
         &prefs_common.summary_col_size[S_COL_MIME], P_INT},
181
        {"summary_col_size_subject", "200",
182
         &prefs_common.summary_col_size[S_COL_SUBJECT], P_INT},
183
        {"summary_col_size_from", "120",
184
         &prefs_common.summary_col_size[S_COL_FROM], P_INT},
185
        {"summary_col_size_date", "118",
186
         &prefs_common.summary_col_size[S_COL_DATE], P_INT},
187
        {"summary_col_size_size", "45",
188
         &prefs_common.summary_col_size[S_COL_SIZE], P_INT},
189
        {"summary_col_size_number", "40",
190
         &prefs_common.summary_col_size[S_COL_NUMBER], P_INT},
191
192
        /* Widget size */
193
        {"folderwin_x", "16", &prefs_common.folderwin_x, P_INT},
194
        {"folderwin_y", "16", &prefs_common.folderwin_y, P_INT},
195
        {"folderview_width", "179", &prefs_common.folderview_width, P_INT},
196
        {"folderview_height", "450", &prefs_common.folderview_height, P_INT},
197
        {"folderview_visible", "TRUE", &prefs_common.folderview_visible,
198
         P_BOOL},
199
200
        {"folder_col_folder", "150", &prefs_common.folder_col_folder, P_INT},
201
        {"folder_col_new", "32", &prefs_common.folder_col_new, P_INT},
202
        {"folder_col_unread", "32", &prefs_common.folder_col_unread, P_INT},
203
        {"folder_col_total", "32", &prefs_common.folder_col_total, P_INT},
204
205
        {"summaryview_width", "600", &prefs_common.summaryview_width, P_INT},
206
        {"summaryview_height", "180", &prefs_common.summaryview_height, P_INT},
207
208
        {"main_messagewin_x", "256", &prefs_common.main_msgwin_x, P_INT},
209
        {"main_messagewin_y", "210", &prefs_common.main_msgwin_y, P_INT},
210
        {"messageview_width", "600", &prefs_common.msgview_width, P_INT},
211
        {"messageview_height", "300", &prefs_common.msgview_height, P_INT},
212
        {"messageview_visible", "TRUE", &prefs_common.msgview_visible, P_BOOL},
213
214
        {"mainview_x", "64", &prefs_common.mainview_x, P_INT},
215
        {"mainview_y", "64", &prefs_common.mainview_y, P_INT},
216
        {"mainview_width", "600", &prefs_common.mainview_width, P_INT},
217
        {"mainview_height", "600", &prefs_common.mainview_height, P_INT},
218
        {"mainwin_x", "64", &prefs_common.mainwin_x, P_INT},
219
        {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT},
220
        {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT},
221
        {"mainwin_height", "600", &prefs_common.mainwin_height, P_INT},
222
        {"messagewin_width", "600", &prefs_common.msgwin_width, P_INT},
223
        {"messagewin_height", "540", &prefs_common.msgwin_height, P_INT},
224
225
        {"mainwin_maximized", "FALSE", &prefs_common.mainwin_maximized, P_BOOL},
226
227
        {"sourcewin_width", "600", &prefs_common.sourcewin_width, P_INT},
228
        {"sourcewin_height", "500", &prefs_common.sourcewin_height, P_INT},
229
        {"compose_x", "32", &prefs_common.compose_x, P_INT},
230
        {"compose_y", "32", &prefs_common.compose_y, P_INT},
231
        {"compose_width", "600", &prefs_common.compose_width, P_INT},
232
        {"compose_height", "560", &prefs_common.compose_height, P_INT},
233
        {"addressbook_x", "32", &prefs_common.addressbook_x, P_INT},
234
        {"addressbook_y", "32", &prefs_common.addressbook_y, P_INT},
235
        {"addressbook_width", "620", &prefs_common.addressbook_width, P_INT},
236
        {"addressbook_height", "360", &prefs_common.addressbook_height, P_INT},
237
238
        /* Message */
239
        {"enable_color", "TRUE", &prefs_common.enable_color, P_BOOL},
240
241
        {"quote_level1_color", "179", &prefs_common.quote_level1_col, P_INT},
242
        {"quote_level2_color", "179", &prefs_common.quote_level2_col, P_INT},
243
        {"quote_level3_color", "179", &prefs_common.quote_level3_col, P_INT},
244
        {"uri_color", "32512", &prefs_common.uri_col, P_INT},
245
        {"signature_color", "0", &prefs_common.sig_col, P_USHORT},
246
        {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
247
         P_BOOL},
248
249
        {"convert_mb_alnum", "FALSE", &prefs_common.conv_mb_alnum, P_BOOL},
250
        {"display_header_pane", "TRUE", &prefs_common.display_header_pane,
251
         P_BOOL},
252
        {"display_header", "TRUE", &prefs_common.display_header, P_BOOL},
253
        {"render_html", "TRUE", &prefs_common.render_html, P_BOOL},
254
        {"line_space", "2", &prefs_common.line_space, P_INT},
255
256
        {"textview_cursor_visible", "FALSE",
257
         &prefs_common.textview_cursor_visible, P_BOOL},
258
259
        {"enable_smooth_scroll", "FALSE", &prefs_common.enable_smooth_scroll,
260
         P_BOOL},
261
        {"scroll_step", "1", &prefs_common.scroll_step, P_INT},
262
        {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL},
263
264
        {"resize_image", "TRUE", &prefs_common.resize_image, P_BOOL},
265
        {"inline_image", "TRUE", &prefs_common.inline_image, P_BOOL},
266
267
        /* Encoding */
268
        {"default_encoding", NULL, &prefs_common.default_encoding, P_STRING},
269
        {"outgoing_charset", NULL, &prefs_common.outgoing_charset, P_STRING},
270
271
        {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL},
272
273
        /* MIME viewer */
274
        {"mime_image_viewer", NULL, &prefs_common.mime_image_viewer, P_STRING},
275
        {"mime_audio_player", NULL, &prefs_common.mime_audio_player, P_STRING},
276
#ifdef G_OS_WIN32
277
        {"mime_open_command", "notepad '%s'", &prefs_common.mime_open_cmd,
278
#else
279
        {"mime_open_command", "gedit '%s'", &prefs_common.mime_open_cmd,
280
#endif
281
         P_STRING},
282
        {"mime_command", NULL, &prefs_common.mime_cmd, P_STRING},
283
284
        /* Junk mail */
285
        {"enable_junk", "FALSE", &prefs_common.enable_junk, P_BOOL},
286
#ifdef G_OS_WIN32
287
        {"junk_learn_command", "bsfilterw -su", &prefs_common.junk_learncmd,
288
         P_STRING},
289
        {"nojunk_learn_command", "bsfilterw -cu",
290
         &prefs_common.nojunk_learncmd, P_STRING},
291
        {"junk_classify_command", "bsfilterw",
292
         &prefs_common.junk_classify_cmd, P_STRING},
293
#else
294
        {"junk_learn_command", "bogofilter -s -I", &prefs_common.junk_learncmd,
295
         P_STRING},
296
        {"nojunk_learn_command", "bogofilter -n -I",
297
         &prefs_common.nojunk_learncmd, P_STRING},
298
        {"junk_classify_command", "bogofilter -I",
299
         &prefs_common.junk_classify_cmd, P_STRING},
300
#endif
301
        {"junk_folder", NULL, &prefs_common.junk_folder, P_STRING},
302
        {"filter_junk_on_receive", "FALSE", &prefs_common.filter_junk_on_recv,
303
         P_BOOL},
304
        {"filter_junk_before", "FALSE", &prefs_common.filter_junk_before,
305
         P_BOOL},
306
        {"delete_junk_on_receive", "TRUE", &prefs_common.delete_junk_on_recv,
307
         P_BOOL},
308
        {"mark_junk_as_read", "FALSE", &prefs_common.mark_junk_as_read, P_BOOL},
309
310
        /* Privacy */
311
        {"auto_check_signatures", "TRUE", &prefs_common.auto_check_signatures,
312
         P_BOOL},
313
        {"gpg_signature_popup", "FALSE", &prefs_common.gpg_signature_popup,
314
         P_BOOL},
315
        {"store_passphrase", "FALSE", &prefs_common.store_passphrase, P_BOOL},
316
        {"store_passphrase_timeout", "0",
317
         &prefs_common.store_passphrase_timeout, P_INT},
318
        {"passphrase_grab", "FALSE", &prefs_common.passphrase_grab, P_BOOL},
319
#ifdef G_OS_WIN32
320
        {"show_gpg_warning", "FALSE", &prefs_common.gpg_warning, P_BOOL},
321
#else
322
        {"show_gpg_warning", "TRUE", &prefs_common.gpg_warning, P_BOOL},
323
#endif
324
325
        /* Interface */
326
        {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL},
327
        {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL},
328
329
        {"always_show_message_when_selected", "FALSE",
330
         &prefs_common.always_show_msg, P_BOOL},
331
        {"open_unread_on_enter", "FALSE", &prefs_common.open_unread_on_enter,
332
         P_BOOL},
333
        {"remember_last_selected", "FALSE",
334
         &prefs_common.remember_last_selected, P_BOOL},
335
        {"mark_as_read_on_new_window", "FALSE",
336
         &prefs_common.mark_as_read_on_new_window, P_BOOL},
337
        {"open_inbox_on_inc", "FALSE", &prefs_common.open_inbox_on_inc, P_BOOL},
338
        {"open_inbox_on_startup", "FALSE", &prefs_common.open_inbox_on_startup,
339
         P_BOOL},
340
        {"immediate_execution", "TRUE", &prefs_common.immediate_exec, P_BOOL},
341
342
#ifdef G_OS_WIN32
343
        {"comply_gnome_hig", "FALSE", &prefs_common.comply_gnome_hig, P_BOOL},
344
#else
345
        {"comply_gnome_hig", "TRUE", &prefs_common.comply_gnome_hig, P_BOOL},
346
#endif
347
348
        {"show_trayicon", "TRUE", &prefs_common.show_trayicon, P_BOOL},
349
        {"minimize_to_tray", "FALSE", &prefs_common.minimize_to_tray, P_BOOL},
350
#ifdef G_OS_WIN32
351
        {"toggle_window_on_trayicon_click", "FALSE",
352
#else
353
        {"toggle_window_on_trayicon_click", "TRUE",
354
#endif
355
         &prefs_common.toggle_window_on_trayicon_click, P_BOOL},
356
357
        /* Other */
358
        {"receive_dialog_mode", "1", &prefs_common.recv_dialog_mode, P_ENUM},
359
        {"no_receive_error_panel", "FALSE", &prefs_common.no_recv_err_panel,
360
         P_BOOL},
361
        {"close_receive_dialog", "TRUE", &prefs_common.close_recv_dialog,
362
         P_BOOL},
363
364
        {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
365
         P_BOOL},
366
367
        {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL},
368
        {"clean_trash_on_exit", "FALSE", &prefs_common.clean_on_exit, P_BOOL},
369
        {"ask_on_cleaning", "TRUE", &prefs_common.ask_on_clean, P_BOOL},
370
        {"warn_queued_on_exit", "TRUE", &prefs_common.warn_queued_on_exit,
371
         P_BOOL},
372
373
        {"logwindow_line_limit", "1000", &prefs_common.logwin_line_limit,
374
         P_INT},
375
376
        /* External commands */
377
#ifdef G_OS_WIN32
378
        {"uri_open_command", NULL, &prefs_common.uri_cmd,
379
#else
380
        {"uri_open_command", DEFAULT_BROWSER_CMD, &prefs_common.uri_cmd,
381
#endif
382
         P_STRING},
383
#ifdef G_OS_WIN32
384
        {"ext_editor_command", "notepad '%s'", &prefs_common.ext_editor_cmd,
385
#else
386
        {"ext_editor_command", "gedit %s", &prefs_common.ext_editor_cmd,
387
#endif
388
         P_STRING},
389
390
        {"use_print_command", "FALSE", &prefs_common.use_print_cmd, P_BOOL},
391
#ifdef G_OS_WIN32
392
        {"print_command", NULL, &prefs_common.print_cmd, P_STRING},
393
#else
394
        {"print_command", "lpr %s", &prefs_common.print_cmd, P_STRING},
395
#endif
396
397
        {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL},
398
        {"ext_inc_path", DEFAULT_INC_PATH, &prefs_common.extinc_cmd, P_STRING},
399
        {"use_ext_sendmail", "FALSE", &prefs_common.use_extsend, P_BOOL},
400
        {"ext_sendmail_cmd", DEFAULT_SENDMAIL_CMD, &prefs_common.extsend_cmd,
401
         P_STRING},
402
403
        /* Advanced */
404
        {"strict_cache_check", "FALSE", &prefs_common.strict_cache_check,
405
         P_BOOL},
406
        {"io_timeout_secs", "60", &prefs_common.io_timeout_secs, P_INT},
407
408
        {NULL, NULL, NULL, P_OTHER}
409
};
410
411
412
PrefsCommon *prefs_common_get(void)
413
{
414
        return &prefs_common;
415
}
416
417
PrefParam *prefs_common_get_params(void)
418
{
419
        return param;
420
}
421
422
void prefs_common_read_config(void)
423
{
424
        FILE *fp;
425
        gchar *path;
426
        gchar buf[PREFSBUFSIZE];
427
428
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
429
430
        prefs_read_config(param, "Common", path, NULL);
431
432
        g_free(path);
433
434
        prefs_common.online_mode = TRUE;
435
436
        prefs_common_junk_filter_list_set();
437
438
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY,
439
                           NULL);
440
        if ((fp = g_fopen(path, "rb")) == NULL) {
441
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
442
                g_free(path);
443
                return;
444
        }
445
        g_free(path);
446
        while (fgets(buf, sizeof(buf), fp) != NULL) {
447
                g_strstrip(buf);
448
                if (buf[0] == '\0') continue;
449
                prefs_common.mime_open_cmd_history =
450
                        add_history(prefs_common.mime_open_cmd_history, buf);
451
        }
452
        fclose(fp);
453
454
        prefs_common.mime_open_cmd_history =
455
                g_list_reverse(prefs_common.mime_open_cmd_history);
456
}
457
458
void prefs_common_write_config(void)
459
{
460
        GList *cur;
461
        FILE *fp;
462
        gchar *path;
463
464
        prefs_write_config(param, "Common", COMMON_RC);
465
466
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY,
467
                           NULL);
468
        if ((fp = g_fopen(path, "wb")) == NULL) {
469
                FILE_OP_ERROR(path, "fopen");
470
                g_free(path);
471
                return;
472
        }
473
474
        for (cur = prefs_common.mime_open_cmd_history;
475
             cur != NULL; cur = cur->next) {
476
                fputs((gchar *)cur->data, fp);
477
                fputc('\n', fp);
478
        }
479
480
        fclose(fp);
481
        g_free(path);
482
}
483
484
static FilterRule *prefs_common_junk_filter_rule_create(gboolean is_manual)
485
{
486
        FilterRule *rule;
487
        FilterCond *cond;
488
        FilterAction *action;
489
        GSList *cond_list = NULL, *action_list = NULL;
490
491
        cond = filter_cond_new(FLT_COND_CMD_TEST, 0, 0, NULL,
492
                               prefs_common.junk_classify_cmd);
493
        cond_list = g_slist_append(NULL, cond);
494
        if (prefs_common.delete_junk_on_recv && !is_manual) {
495
                action = filter_action_new(FLT_ACTION_COPY,
496
                                           prefs_common.junk_folder);
497
                action_list = g_slist_append(NULL, action);
498
                action = filter_action_new(FLT_ACTION_DELETE, NULL);
499
                action_list = g_slist_append(action_list, action);
500
        } else {
501
                action = filter_action_new(FLT_ACTION_MOVE,
502
                                           prefs_common.junk_folder);
503
                action_list = g_slist_append(NULL, action);
504
        }
505
506
        if (prefs_common.mark_junk_as_read) {
507
                action = filter_action_new(FLT_ACTION_MARK_READ, NULL);
508
                action_list = g_slist_append(action_list, action);
509
        }
510
511
        if (is_manual)
512
                rule = filter_rule_new(_("Junk mail filter (manual)"), FLT_OR,
513
                                        cond_list, action_list);
514
        else
515
                rule = filter_rule_new(_("Junk mail filter"), FLT_OR,
516
                                       cond_list, action_list);
517
518
        return rule;
519
}
520
521
void prefs_common_junk_filter_list_set(void)
522
{
523
        FilterRule *rule;
524
525
        if (prefs_common.junk_fltlist) {
526
                filter_rule_list_free(prefs_common.junk_fltlist);
527
                prefs_common.junk_fltlist = NULL;
528
        }
529
        if (prefs_common.manual_junk_fltlist) {
530
                filter_rule_list_free(prefs_common.manual_junk_fltlist);
531
                prefs_common.manual_junk_fltlist = NULL;
532
        }
533
534
        if (!prefs_common.junk_classify_cmd || !prefs_common.junk_folder)
535
                return;
536
537
        rule = prefs_common_junk_filter_rule_create(FALSE);
538
        prefs_common.junk_fltlist = g_slist_append(NULL, rule);
539
540
        rule = prefs_common_junk_filter_rule_create(TRUE);
541
        prefs_common.manual_junk_fltlist = g_slist_append(NULL, rule);
542
}
543
544
void prefs_common_junk_folder_rename_path(const gchar *old_path,
545
                                          const gchar *new_path)
546
{
547
        gint len;
548
        gchar *base;
549
        gchar *dest_path;
550
551
        g_return_if_fail(old_path != NULL);
552
        g_return_if_fail(new_path != NULL);
553
554
        if (!prefs_common.junk_folder)
555
                return;
556
557
        len = strlen(prefs_common.junk_folder);
558
559
        if (!strncmp(old_path, prefs_common.junk_folder, len)) {
560
                base = prefs_common.junk_folder + len;
561
                if (*base != '/' && *base != '\0')
562
                        return;
563
                while (*base == '/') base++;
564
                if (*base == '\0')
565
                        dest_path = g_strdup(new_path);
566
                else
567
                        dest_path = g_strconcat(new_path, "/", base, NULL);
568
                debug_print("prefs_common_junk_folder_rename_path(): "
569
                            "renaming %s -> %s\n", prefs_common.junk_folder,
570
                            dest_path);
571
                g_free(prefs_common.junk_folder);
572
                prefs_common.junk_folder = dest_path;
573
                prefs_common_junk_filter_list_set();
574
        }
575
}