Statistics
| Revision:

root / libsylph / prefs_common.c @ 1260

History | View | Annotate | Download (18.3 kB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2006 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
87
        {"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL},
88
89
        /* Quote */
90
        {"reply_quote_mark", "> ", &prefs_common.quotemark, P_STRING},
91
        {"reply_quote_format", "On %d\\n%f wrote:\\n\\n%Q",
92
         &prefs_common.quotefmt, P_STRING},
93
94
        {"forward_quote_mark", "> ", &prefs_common.fw_quotemark, P_STRING},
95
        {"forward_quote_format",
96
         "\\n\\nBegin forwarded message:\\n\\n"
97
         "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
98
         "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M",
99
         &prefs_common.fw_quotefmt, P_STRING},
100
101
        /* Spelling */
102
        {"check_spell", "FALSE", &prefs_common.check_spell, P_BOOL},
103
        {"spell_lang", "en", &prefs_common.spell_lang, P_STRING},
104
105
        /* Display */
106
        {"message_font_name", DEFAULT_MESSAGE_FONT, &prefs_common.textfont,
107
         P_STRING},
108
109
        {"display_folder_unread_num", "TRUE",
110
         &prefs_common.display_folder_unread, P_BOOL},
111
        {"display_folder_num_columns", "FALSE",
112
         &prefs_common.display_folder_num_columns, P_BOOL},
113
114
        {"newsgroup_abbrev_len", "16", &prefs_common.ng_abbrev_len, P_INT},
115
116
        {"translate_header", "TRUE", &prefs_common.trans_hdr, P_BOOL},
117
118
        /* Display: Summary View */
119
        {"enable_swap_from", "FALSE", &prefs_common.swap_from, P_BOOL},
120
        {"date_format", "%y/%m/%d(%a) %H:%M", &prefs_common.date_format,
121
         P_STRING},
122
        {"expand_thread", "TRUE", &prefs_common.expand_thread, P_BOOL},
123
124
        {"enable_rules_hint", "TRUE", &prefs_common.enable_rules_hint, P_BOOL},
125
        {"bold_unread", "TRUE", &prefs_common.bold_unread, P_BOOL},
126
127
        {"toolbar_style", "3", &prefs_common.toolbar_style, P_ENUM},
128
        {"show_searchbar", "TRUE", &prefs_common.show_searchbar, P_BOOL},
129
        {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL},
130
131
        {"summary_col_show_mark", "TRUE",
132
         &prefs_common.summary_col_visible[S_COL_MARK], P_BOOL},
133
        {"summary_col_show_unread", "TRUE",
134
         &prefs_common.summary_col_visible[S_COL_UNREAD], P_BOOL},
135
        {"summary_col_show_mime", "TRUE",
136
         &prefs_common.summary_col_visible[S_COL_MIME], P_BOOL},
137
        {"summary_col_show_subject", "TRUE",
138
         &prefs_common.summary_col_visible[S_COL_SUBJECT], P_BOOL},
139
        {"summary_col_show_from", "TRUE",
140
         &prefs_common.summary_col_visible[S_COL_FROM], P_BOOL},
141
        {"summary_col_show_date", "TRUE",
142
         &prefs_common.summary_col_visible[S_COL_DATE], P_BOOL},
143
        {"summary_col_show_size", "TRUE",
144
         &prefs_common.summary_col_visible[S_COL_SIZE], P_BOOL},
145
        {"summary_col_show_number", "FALSE",
146
         &prefs_common.summary_col_visible[S_COL_NUMBER], P_BOOL},
147
148
        {"summary_col_pos_mark", "0",
149
          &prefs_common.summary_col_pos[S_COL_MARK], P_INT},
150
        {"summary_col_pos_unread", "1",
151
          &prefs_common.summary_col_pos[S_COL_UNREAD], P_INT},
152
        {"summary_col_pos_mime", "2",
153
          &prefs_common.summary_col_pos[S_COL_MIME], P_INT},
154
        {"summary_col_pos_subject", "3",
155
          &prefs_common.summary_col_pos[S_COL_SUBJECT], P_INT},
156
        {"summary_col_pos_from", "4",
157
          &prefs_common.summary_col_pos[S_COL_FROM], P_INT},
158
        {"summary_col_pos_date", "5",
159
          &prefs_common.summary_col_pos[S_COL_DATE], P_INT},
160
        {"summary_col_pos_size", "6",
161
          &prefs_common.summary_col_pos[S_COL_SIZE], P_INT},
162
        {"summary_col_pos_number", "7",
163
          &prefs_common.summary_col_pos[S_COL_NUMBER], P_INT},
164
165
        {"summary_col_size_mark", "10",
166
         &prefs_common.summary_col_size[S_COL_MARK], P_INT},
167
        {"summary_col_size_unread", "13",
168
         &prefs_common.summary_col_size[S_COL_UNREAD], P_INT},
169
        {"summary_col_size_mime", "10",
170
         &prefs_common.summary_col_size[S_COL_MIME], P_INT},
171
        {"summary_col_size_subject", "200",
172
         &prefs_common.summary_col_size[S_COL_SUBJECT], P_INT},
173
        {"summary_col_size_from", "120",
174
         &prefs_common.summary_col_size[S_COL_FROM], P_INT},
175
        {"summary_col_size_date", "118",
176
         &prefs_common.summary_col_size[S_COL_DATE], P_INT},
177
        {"summary_col_size_size", "45",
178
         &prefs_common.summary_col_size[S_COL_SIZE], P_INT},
179
        {"summary_col_size_number", "40",
180
         &prefs_common.summary_col_size[S_COL_NUMBER], P_INT},
181
182
        /* Widget size */
183
        {"folderwin_x", "16", &prefs_common.folderwin_x, P_INT},
184
        {"folderwin_y", "16", &prefs_common.folderwin_y, P_INT},
185
        {"folderview_width", "179", &prefs_common.folderview_width, P_INT},
186
        {"folderview_height", "450", &prefs_common.folderview_height, P_INT},
187
        {"folderview_visible", "TRUE", &prefs_common.folderview_visible,
188
         P_BOOL},
189
190
        {"folder_col_folder", "150", &prefs_common.folder_col_folder, P_INT},
191
        {"folder_col_new", "32", &prefs_common.folder_col_new, P_INT},
192
        {"folder_col_unread", "32", &prefs_common.folder_col_unread, P_INT},
193
        {"folder_col_total", "32", &prefs_common.folder_col_total, P_INT},
194
195
        {"summaryview_width", "600", &prefs_common.summaryview_width, P_INT},
196
        {"summaryview_height", "180", &prefs_common.summaryview_height, P_INT},
197
198
        {"main_messagewin_x", "256", &prefs_common.main_msgwin_x, P_INT},
199
        {"main_messagewin_y", "210", &prefs_common.main_msgwin_y, P_INT},
200
        {"messageview_width", "600", &prefs_common.msgview_width, P_INT},
201
        {"messageview_height", "300", &prefs_common.msgview_height, P_INT},
202
        {"messageview_visible", "TRUE", &prefs_common.msgview_visible, P_BOOL},
203
204
        {"mainview_x", "64", &prefs_common.mainview_x, P_INT},
205
        {"mainview_y", "64", &prefs_common.mainview_y, P_INT},
206
        {"mainview_width", "600", &prefs_common.mainview_width, P_INT},
207
        {"mainview_height", "600", &prefs_common.mainview_height, P_INT},
208
        {"mainwin_x", "64", &prefs_common.mainwin_x, P_INT},
209
        {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT},
210
        {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT},
211
        {"mainwin_height", "600", &prefs_common.mainwin_height, P_INT},
212
        {"messagewin_width", "600", &prefs_common.msgwin_width, P_INT},
213
        {"messagewin_height", "540", &prefs_common.msgwin_height, P_INT},
214
215
        {"mainwin_maximized", "FALSE", &prefs_common.mainwin_maximized, P_BOOL},
216
217
        {"sourcewin_width", "600", &prefs_common.sourcewin_width, P_INT},
218
        {"sourcewin_height", "500", &prefs_common.sourcewin_height, P_INT},
219
        {"compose_x", "32", &prefs_common.compose_x, P_INT},
220
        {"compose_y", "32", &prefs_common.compose_y, P_INT},
221
        {"compose_width", "600", &prefs_common.compose_width, P_INT},
222
        {"compose_height", "560", &prefs_common.compose_height, P_INT},
223
        {"addressbook_x", "32", &prefs_common.addressbook_x, P_INT},
224
        {"addressbook_y", "32", &prefs_common.addressbook_y, P_INT},
225
        {"addressbook_width", "620", &prefs_common.addressbook_width, P_INT},
226
        {"addressbook_height", "360", &prefs_common.addressbook_height, P_INT},
227
228
        /* Message */
229
        {"enable_color", "TRUE", &prefs_common.enable_color, P_BOOL},
230
231
        {"quote_level1_color", "179", &prefs_common.quote_level1_col, P_INT},
232
        {"quote_level2_color", "179", &prefs_common.quote_level2_col, P_INT},
233
        {"quote_level3_color", "179", &prefs_common.quote_level3_col, P_INT},
234
        {"uri_color", "32512", &prefs_common.uri_col, P_INT},
235
        {"signature_color", "0", &prefs_common.sig_col, P_USHORT},
236
        {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
237
         P_BOOL},
238
239
        {"convert_mb_alnum", "FALSE", &prefs_common.conv_mb_alnum, P_BOOL},
240
        {"display_header_pane", "TRUE", &prefs_common.display_header_pane,
241
         P_BOOL},
242
        {"display_header", "TRUE", &prefs_common.display_header, P_BOOL},
243
        {"render_html", "TRUE", &prefs_common.render_html, P_BOOL},
244
        {"line_space", "2", &prefs_common.line_space, P_INT},
245
246
        {"textview_cursor_visible", "FALSE",
247
         &prefs_common.textview_cursor_visible, P_BOOL},
248
249
        {"enable_smooth_scroll", "FALSE", &prefs_common.enable_smooth_scroll,
250
         P_BOOL},
251
        {"scroll_step", "1", &prefs_common.scroll_step, P_INT},
252
        {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL},
253
254
        {"resize_image", "TRUE", &prefs_common.resize_image, P_BOOL},
255
        {"inline_image", "TRUE", &prefs_common.inline_image, P_BOOL},
256
257
        /* Encoding */
258
        {"default_encoding", NULL, &prefs_common.default_encoding, P_STRING},
259
        {"outgoing_charset", NULL, &prefs_common.outgoing_charset, P_STRING},
260
261
        {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL},
262
263
        /* MIME viewer */
264
        {"mime_image_viewer", NULL, &prefs_common.mime_image_viewer, P_STRING},
265
        {"mime_audio_player", NULL, &prefs_common.mime_audio_player, P_STRING},
266
#ifdef G_OS_WIN32
267
        {"mime_open_command", "notepad '%s'", &prefs_common.mime_open_cmd,
268
#else
269
        {"mime_open_command", "gedit '%s'", &prefs_common.mime_open_cmd,
270
#endif
271
         P_STRING},
272
        {"mime_command", NULL, &prefs_common.mime_cmd, P_STRING},
273
274
        /* Junk mail */
275
        {"enable_junk", "FALSE", &prefs_common.enable_junk, P_BOOL},
276
#ifdef G_OS_WIN32
277
        {"junk_learn_command", "bsfilterw -su", &prefs_common.junk_learncmd,
278
         P_STRING},
279
        {"nojunk_learn_command", "bsfilterw -cu",
280
         &prefs_common.nojunk_learncmd, P_STRING},
281
        {"junk_classify_command", "bsfilterw",
282
         &prefs_common.junk_classify_cmd, P_STRING},
283
#else
284
        {"junk_learn_command", "bogofilter -s -I", &prefs_common.junk_learncmd,
285
         P_STRING},
286
        {"nojunk_learn_command", "bogofilter -n -I",
287
         &prefs_common.nojunk_learncmd, P_STRING},
288
        {"junk_classify_command", "bogofilter -I",
289
         &prefs_common.junk_classify_cmd, P_STRING},
290
#endif
291
        {"junk_folder", NULL, &prefs_common.junk_folder, P_STRING},
292
        {"filter_junk_on_receive", "FALSE", &prefs_common.filter_junk_on_recv,
293
         P_BOOL},
294
        {"filter_junk_before", "FALSE", &prefs_common.filter_junk_before,
295
         P_BOOL},
296
        {"delete_junk_on_receive", "TRUE", &prefs_common.delete_junk_on_recv,
297
         P_BOOL},
298
        {"mark_junk_as_read", "FALSE", &prefs_common.mark_junk_as_read, P_BOOL},
299
300
        /* Privacy */
301
        {"auto_check_signatures", "TRUE", &prefs_common.auto_check_signatures,
302
         P_BOOL},
303
        {"gpg_signature_popup", "FALSE", &prefs_common.gpg_signature_popup,
304
         P_BOOL},
305
        {"store_passphrase", "FALSE", &prefs_common.store_passphrase, P_BOOL},
306
        {"store_passphrase_timeout", "0",
307
         &prefs_common.store_passphrase_timeout, P_INT},
308
        {"passphrase_grab", "FALSE", &prefs_common.passphrase_grab, P_BOOL},
309
#ifdef G_OS_WIN32
310
        {"show_gpg_warning", "FALSE", &prefs_common.gpg_warning, P_BOOL},
311
#else
312
        {"show_gpg_warning", "TRUE", &prefs_common.gpg_warning, P_BOOL},
313
#endif
314
315
        /* Interface */
316
        {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL},
317
        {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL},
318
319
        {"always_show_message_when_selected", "FALSE",
320
         &prefs_common.always_show_msg, P_BOOL},
321
        {"open_unread_on_enter", "FALSE", &prefs_common.open_unread_on_enter,
322
         P_BOOL},
323
        {"mark_as_read_on_new_window", "FALSE",
324
         &prefs_common.mark_as_read_on_new_window, P_BOOL},
325
        {"open_inbox_on_inc", "FALSE", &prefs_common.open_inbox_on_inc, P_BOOL},
326
        {"open_inbox_on_startup", "FALSE", &prefs_common.open_inbox_on_startup,
327
         P_BOOL},
328
        {"immediate_execution", "TRUE", &prefs_common.immediate_exec, P_BOOL},
329
330
#ifdef G_OS_WIN32
331
        {"comply_gnome_hig", "FALSE", &prefs_common.comply_gnome_hig, P_BOOL},
332
#else
333
        {"comply_gnome_hig", "TRUE", &prefs_common.comply_gnome_hig, P_BOOL},
334
#endif
335
336
        {"show_trayicon", "TRUE", &prefs_common.show_trayicon, P_BOOL},
337
        {"minimize_to_tray", "FALSE", &prefs_common.minimize_to_tray, P_BOOL},
338
339
        /* Other */
340
        {"receive_dialog_mode", "1", &prefs_common.recv_dialog_mode, P_ENUM},
341
        {"no_receive_error_panel", "FALSE", &prefs_common.no_recv_err_panel,
342
         P_BOOL},
343
        {"close_receive_dialog", "TRUE", &prefs_common.close_recv_dialog,
344
         P_BOOL},
345
346
        {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
347
         P_BOOL},
348
349
        {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL},
350
        {"clean_trash_on_exit", "FALSE", &prefs_common.clean_on_exit, P_BOOL},
351
        {"ask_on_cleaning", "TRUE", &prefs_common.ask_on_clean, P_BOOL},
352
        {"warn_queued_on_exit", "TRUE", &prefs_common.warn_queued_on_exit,
353
         P_BOOL},
354
355
        {"logwindow_line_limit", "1000", &prefs_common.logwin_line_limit,
356
         P_INT},
357
358
        /* External commands */
359
#ifdef G_OS_WIN32
360
        {"uri_open_command", NULL, &prefs_common.uri_cmd,
361
#else
362
        {"uri_open_command", DEFAULT_BROWSER_CMD, &prefs_common.uri_cmd,
363
#endif
364
         P_STRING},
365
#ifdef G_OS_WIN32
366
        {"print_command", NULL, &prefs_common.print_cmd, P_STRING},
367
#else
368
        {"print_command", "lpr %s", &prefs_common.print_cmd, P_STRING},
369
#endif
370
#ifdef G_OS_WIN32
371
        {"ext_editor_command", "notepad '%s'", &prefs_common.ext_editor_cmd,
372
#else
373
        {"ext_editor_command", "gedit %s", &prefs_common.ext_editor_cmd,
374
#endif
375
         P_STRING},
376
377
        {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL},
378
        {"ext_inc_path", DEFAULT_INC_PATH, &prefs_common.extinc_cmd, P_STRING},
379
        {"use_ext_sendmail", "FALSE", &prefs_common.use_extsend, P_BOOL},
380
        {"ext_sendmail_cmd", DEFAULT_SENDMAIL_CMD, &prefs_common.extsend_cmd,
381
         P_STRING},
382
383
        /* Advanced */
384
        {"strict_cache_check", "FALSE", &prefs_common.strict_cache_check,
385
         P_BOOL},
386
        {"io_timeout_secs", "60", &prefs_common.io_timeout_secs, P_INT},
387
388
        {NULL, NULL, NULL, P_OTHER}
389
};
390
391
392
PrefParam *prefs_common_get_params(void)
393
{
394
        return param;
395
}
396
397
void prefs_common_read_config(void)
398
{
399
        FILE *fp;
400
        gchar *path;
401
        gchar buf[PREFSBUFSIZE];
402
403
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
404
405
        prefs_read_config(param, "Common", path, NULL);
406
407
#ifdef G_OS_WIN32
408
        if (!is_file_exist(path)) {
409
                if (conv_is_ja_locale()) {
410
                        g_free(prefs_common.textfont);
411
                        prefs_common.textfont = g_strdup("MS Gothic 12");
412
                }
413
        }
414
#endif
415
416
        g_free(path);
417
418
        prefs_common.online_mode = TRUE;
419
420
        prefs_common_junk_filter_list_set();
421
422
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY,
423
                           NULL);
424
        if ((fp = g_fopen(path, "rb")) == NULL) {
425
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
426
                g_free(path);
427
                return;
428
        }
429
        g_free(path);
430
        while (fgets(buf, sizeof(buf), fp) != NULL) {
431
                g_strstrip(buf);
432
                if (buf[0] == '\0') continue;
433
                prefs_common.mime_open_cmd_history =
434
                        add_history(prefs_common.mime_open_cmd_history, buf);
435
        }
436
        fclose(fp);
437
438
        prefs_common.mime_open_cmd_history =
439
                g_list_reverse(prefs_common.mime_open_cmd_history);
440
}
441
442
void prefs_common_write_config(void)
443
{
444
        GList *cur;
445
        FILE *fp;
446
        gchar *path;
447
448
        prefs_write_config(param, "Common", COMMON_RC);
449
450
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY,
451
                           NULL);
452
        if ((fp = g_fopen(path, "wb")) == NULL) {
453
                FILE_OP_ERROR(path, "fopen");
454
                g_free(path);
455
                return;
456
        }
457
458
        for (cur = prefs_common.mime_open_cmd_history;
459
             cur != NULL; cur = cur->next) {
460
                fputs((gchar *)cur->data, fp);
461
                fputc('\n', fp);
462
        }
463
464
        fclose(fp);
465
        g_free(path);
466
}
467
468
static FilterRule *prefs_common_junk_filter_rule_create(gboolean is_manual)
469
{
470
        FilterRule *rule;
471
        FilterCond *cond;
472
        FilterAction *action;
473
        GSList *cond_list = NULL, *action_list = NULL;
474
475
        cond = filter_cond_new(FLT_COND_CMD_TEST, 0, 0, NULL,
476
                               prefs_common.junk_classify_cmd);
477
        cond_list = g_slist_append(NULL, cond);
478
        if (prefs_common.delete_junk_on_recv && !is_manual) {
479
                action = filter_action_new(FLT_ACTION_COPY,
480
                                           prefs_common.junk_folder);
481
                action_list = g_slist_append(NULL, action);
482
                action = filter_action_new(FLT_ACTION_DELETE, NULL);
483
                action_list = g_slist_append(action_list, action);
484
        } else {
485
                action = filter_action_new(FLT_ACTION_MOVE,
486
                                           prefs_common.junk_folder);
487
                action_list = g_slist_append(NULL, action);
488
        }
489
490
        if (prefs_common.mark_junk_as_read) {
491
                action = filter_action_new(FLT_ACTION_MARK_READ, NULL);
492
                action_list = g_slist_append(action_list, action);
493
        }
494
495
        if (is_manual)
496
                rule = filter_rule_new(_("Junk mail filter (manual)"), FLT_OR,
497
                                        cond_list, action_list);
498
        else
499
                rule = filter_rule_new(_("Junk mail filter"), FLT_OR,
500
                                       cond_list, action_list);
501
502
        return rule;
503
}
504
505
void prefs_common_junk_filter_list_set(void)
506
{
507
        FilterRule *rule;
508
509
        if (prefs_common.junk_fltlist) {
510
                filter_rule_list_free(prefs_common.junk_fltlist);
511
                prefs_common.junk_fltlist = NULL;
512
        }
513
        if (prefs_common.manual_junk_fltlist) {
514
                filter_rule_list_free(prefs_common.manual_junk_fltlist);
515
                prefs_common.manual_junk_fltlist = NULL;
516
        }
517
518
        if (!prefs_common.junk_classify_cmd || !prefs_common.junk_folder)
519
                return;
520
521
        rule = prefs_common_junk_filter_rule_create(FALSE);
522
        prefs_common.junk_fltlist = g_slist_append(NULL, rule);
523
524
        rule = prefs_common_junk_filter_rule_create(TRUE);
525
        prefs_common.manual_junk_fltlist = g_slist_append(NULL, rule);
526
}