Fix CID 1491401 and 1491402: (possible) modulo by zero.
[claws.git] / src / prefs_common.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef __PREFS_COMMON_H__
20 #define __PREFS_COMMON_H__
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #include "claws-features.h"
25 #endif
26
27 #include <glib.h>
28
29 #include "mainwindow.h"
30 #include "summaryview.h"
31 #include "folderview.h"
32 #include "codeconv.h"
33 #include "textview.h"
34 #include "procmime.h"
35 #include "prefs_msg_colors.h"
36 #include "prefs_summary_open.h"
37
38 #define CLAWS_CONFIG_VERSION 4
39
40 typedef struct _PrefsCommon     PrefsCommon;
41
42 typedef enum {
43         RECV_DIALOG_ALWAYS,
44         RECV_DIALOG_MANUAL,
45         RECV_DIALOG_NEVER
46 } RecvDialogMode;
47
48 typedef enum {
49         COMPOSE_DND_ASK,
50         COMPOSE_DND_INSERT,
51         COMPOSE_DND_ATTACH
52 } ComposeDndInsertOrAttach;
53
54 typedef enum {
55         CTE_AUTO,
56         CTE_BASE64,
57         CTE_QUOTED_PRINTABLE,
58         CTE_8BIT
59 } TransferEncodingMethod;
60
61 typedef enum
62 {
63 /* U = unread, N = new, M = marked */
64         SELECTONENTRY_NOTHING,
65         SELECTONENTRY_UNM,
66         SELECTONENTRY_UMN,
67         SELECTONENTRY_NUM,
68         SELECTONENTRY_NMU,
69         SELECTONENTRY_MNU,
70         SELECTONENTRY_MUN,
71         SELECTONENTRY_LAST
72 } SelectOnEntry;
73
74 typedef enum
75 {
76         ACTION_UNSET = 0, /* for backward compatibility */
77         ACTION_OLDEST_MARKED,
78         ACTION_OLDEST_NEW,
79         ACTION_OLDEST_UNREAD,
80         ACTION_LAST_OPENED,
81         ACTION_NEWEST_LIST,
82         ACTION_NOTHING,
83         ACTION_OLDEST_LIST,
84         ACTION_NEWEST_MARKED,
85         ACTION_NEWEST_NEW,
86         ACTION_NEWEST_UNREAD
87 } EntryAction;
88
89 typedef enum
90 {
91         NEXTUNREADMSGDIALOG_ALWAYS,
92         NEXTUNREADMSGDIALOG_ASSUME_YES,
93         NEXTUNREADMSGDIALOG_ASSUME_NO
94 } NextUnreadMsgDialogShow;
95
96 typedef enum
97 {
98         SHOW_NAME,
99         SHOW_ADDR,
100         SHOW_BOTH
101 } SummaryFromShow;
102
103 typedef enum
104 {
105         AVATARS_DISABLE = 0,
106         AVATARS_ENABLE_CAPTURE = 1,
107         AVATARS_ENABLE_RENDER = 2,
108         AVATARS_ENABLE_BOTH = 3
109 } EnableAvatars;
110
111 typedef enum
112 {
113         COL_MISSPELLED,
114         COL_QUOTE_LEVEL1,
115         COL_QUOTE_LEVEL2,
116         COL_QUOTE_LEVEL3,
117         COL_QUOTE_LEVEL1_BG,
118         COL_QUOTE_LEVEL2_BG,
119         COL_QUOTE_LEVEL3_BG,
120         COL_URI,
121         COL_TGT_FOLDER,
122         COL_SIGNATURE,
123         COL_EMPHASIS,
124         COL_DEFAULT_HEADER,
125         COL_DEFAULT_HEADER_BG,
126         COL_TAGS,
127         COL_TAGS_BG,
128         COL_QS_ACTIVE,
129         COL_QS_ACTIVE_BG,
130         COL_QS_ERROR,
131         COL_QS_ERROR_BG,
132         COL_LOG_MSG,
133         COL_LOG_WARN,
134         COL_LOG_ERROR,
135         COL_LOG_IN,
136         COL_LOG_OUT,
137         COL_LOG_STATUS_OK,
138         COL_LOG_STATUS_NOK,
139         COL_LOG_STATUS_SKIP,
140         COL_NEW,
141         COL_DIFF_ADDED,
142         COL_DIFF_DELETED,
143         COL_DIFF_HUNK,
144         COL_LAST_COLOR_INDEX
145 } ColorIndex;
146
147 struct _PrefsCommon
148 {
149         gint config_version;
150
151         /* Receive */
152         gboolean use_extinc;
153         gchar *extinc_cmd;
154         gboolean scan_all_after_inc;
155         gboolean autochk_newmail;
156         gint autochk_itv;
157         gboolean chk_on_startup;
158         gboolean open_inbox_on_inc;
159         gboolean newmail_notify_auto;
160         gboolean newmail_notify_manu;
161         gchar   *newmail_notify_cmd;
162         RecvDialogMode recv_dialog_mode;
163         gint receivewin_width;
164         gint receivewin_height;
165         gboolean close_recv_dialog;
166         gboolean no_recv_err_panel;
167
168         /* Send */
169         gboolean savemsg;
170         gboolean confirm_send_queued_messages;
171         gboolean send_dialog_invisible;
172         gint sendwin_width;
173         gint sendwin_height;
174         gchar *outgoing_charset;
175         TransferEncodingMethod encoding_method;
176         gboolean outgoing_fallback_to_ascii;
177         gboolean rewrite_first_from;
178         gboolean warn_empty_subj;
179         gint warn_sending_many_recipients_num;
180         gboolean hide_timezone;
181         gboolean allow_jisx0201_kana;
182
183         /* Compose */
184         gint undolevels;
185         gint linewrap_len;
186         gboolean linewrap_quote;
187         gboolean linewrap_pastes;
188         gboolean primary_paste_unselects;
189         gboolean autowrap;
190         gboolean auto_indent;
191         gboolean auto_exteditor;
192         gboolean reply_account_autosel;
193         gboolean default_reply_list;
194         gboolean forward_account_autosel;
195         gboolean reedit_account_autosel;
196         gboolean show_ruler;
197         gboolean autosave;
198         gint autosave_length;
199         gboolean autosave_encrypted;
200         gboolean warn_large_insert;
201         gint warn_large_insert_size;
202         gboolean compose_no_markup;
203         ComposeDndInsertOrAttach compose_dnd_mode;
204         gboolean compose_with_format;
205         gchar *compose_subject_format;
206         gchar *compose_body_format;
207         gboolean show_compose_margin;
208         gboolean type_any_header;
209
210         /* Quote */
211         gboolean reply_with_quote;
212         gchar *quotemark;
213         gchar *quotefmt;
214         gchar *fw_quotemark;
215         gchar *fw_quotefmt;
216         gboolean forward_as_attachment;
217         gboolean redirect_keep_from;
218         gchar *quote_chars;
219         
220         gboolean enable_aspell;
221         gchar *dictionary;
222         gchar *alt_dictionary;
223         gboolean check_while_typing;
224         gboolean recheck_when_changing_dict;
225         gboolean use_alternate;
226         gboolean use_both_dicts;
227
228         /* Display */
229         /* fonts */
230         gchar *textfont;
231         gchar *printfont;
232         gchar *boldfont;
233         gchar *normalfont;
234         gchar *smallfont;
235         gchar *titlefont;
236         gboolean use_different_print_font;
237         gboolean derive_from_normal_font;
238
239         /* custom colors */
240         ColorlabelPrefs custom_colorlabel[COLORLABELS];
241
242         /* program colors */
243         gulong color[COL_LAST_COLOR_INDEX];
244
245         /* image viewer */
246         gboolean display_img;
247         gboolean resize_img;
248         gboolean inline_img;
249         gboolean fit_img_height;
250
251         gboolean trans_hdr;
252         gint display_folder_unread;
253         gint ng_abbrev_len;
254
255         gboolean show_searchbar;
256         gboolean swap_from;
257         gboolean use_addr_book;
258         gchar *date_format;
259         gboolean *msgview_date_format;
260
261         gboolean use_stripes_everywhere;
262         gboolean use_stripes_in_summaries; /* overrides if use_stripes_everywhere is set to TRUE */
263         gint stripes_color_offset;
264         gboolean enable_hscrollbar;
265         gboolean bold_unread;
266         gboolean next_on_delete;
267         gboolean thread_by_subject;
268         gint thread_by_subject_max_age; /*!< Max. age of a thread which was threaded
269                                          *   by subject (days) */
270         FolderSortKey default_sort_key;
271         FolderSortType default_sort_type;
272         gboolean folder_default_thread;
273         gboolean folder_default_thread_collapsed;
274         gboolean folder_default_hide_read_threads;
275         gboolean folder_default_hide_read_msgs;
276         gboolean folder_default_hide_del_msgs;
277
278         gchar *last_opened_folder;
279         gboolean goto_last_folder_on_startup;
280
281         ToolbarStyle toolbar_style;
282         gboolean toolbar_detachable;
283         gboolean show_statusbar;
284         gboolean show_col_headers;
285
286         gint folderview_vscrollbar_policy;
287
288         /* Filtering */
289         GSList *fltlist;
290
291         gint kill_score;
292         gint important_score;
293
294         /* Actions */
295         GSList *actions_list;
296
297         /* Summary lock column headers */
298         gboolean summary_col_lock;
299
300         /* Summary columns visibility, position and size */
301         gboolean summary_col_visible[N_SUMMARY_COLS];
302         gint summary_col_pos[N_SUMMARY_COLS];
303         gint summary_col_size[N_SUMMARY_COLS];
304
305         gboolean folder_col_visible[N_FOLDER_COLS];
306         gint folder_col_pos[N_FOLDER_COLS];
307         gint folder_col_size[N_FOLDER_COLS];
308
309         /* Widget visibility, position and size */
310         gint folderwin_x;
311         gint folderwin_y;
312         gint folderview_width;
313         gint folderview_height;
314         gboolean folderview_visible;
315
316         gint summaryview_width;
317         gint summaryview_height;
318
319         gint main_msgwin_x;
320         gint main_msgwin_y;
321         gint msgview_width;
322         gint msgview_height;
323         gboolean msgview_visible;
324
325         gint mainview_x;
326         gint mainview_y;
327         gint mainview_width;
328         gint mainview_height;
329         gint mainwin_x;
330         gint mainwin_y;
331         gint mainwin_width;
332         gint mainwin_height;
333         gint mainwin_maximised;
334         gint mainwin_fullscreen;
335         gint mainwin_menubar;
336
337         gint msgwin_width;
338         gint msgwin_height;
339
340         gint mimeview_tree_height;
341         
342         gint sourcewin_width;
343         gint sourcewin_height;
344
345         gint compose_width;
346         gint compose_height;
347         gint compose_notebook_height;
348         gint compose_x;
349         gint compose_y;
350
351         /* Message */
352         gboolean enable_color;
353         gboolean enable_bgcolor;
354         gboolean recycle_quote_colors;
355         gboolean display_header_pane;
356         gboolean display_header;
357         gboolean display_xface;
358         gboolean save_xface;
359         gint line_space;
360         gboolean render_html;
361         gboolean invoke_plugin_on_html;
362         gboolean promote_html_part;
363         gboolean textview_cursor_visible;
364         gboolean enable_smooth_scroll;
365         gint scroll_step;
366         gboolean scroll_halfpage;
367         gboolean hide_quoted;
368         gboolean respect_flowed_format;
369         gboolean show_all_headers;
370
371         gboolean show_other_header;
372         GSList *disphdr_list;
373
374         gboolean attach_desc;
375
376         /* MIME viewer */
377         gchar *mime_textviewer;
378         gchar *mime_open_cmd;
379         gchar *attach_save_dir;
380         gchar *attach_load_dir;
381
382         GList *mime_open_cmd_history;
383         gboolean show_inline_attachments;
384
385         /* Addressbook */
386         gboolean addressbook_use_editaddress_dialog;
387         gint addressbook_hpaned_pos;
388         gint addressbook_vpaned_pos;
389         GList *addressbook_custom_attributes;
390
391         /* Interface */
392         LayoutType layout_mode;
393
394         gint statusbar_update_step;
395         gboolean emulate_emacs;
396
397         gboolean open_selected_on_folder_open;
398         gboolean open_selected_on_search_results;
399         gboolean open_selected_on_prevnext;
400         gboolean open_selected_on_deletemove;
401         gboolean open_selected_on_directional;
402         gboolean always_show_msg;
403
404         gboolean mark_as_read_on_new_window;
405         gboolean mark_as_read_delay;
406         gboolean immediate_exec;
407         SelectOnEntry select_on_entry;
408         gboolean show_tooltips;
409
410         EntryAction summary_select_prio[SUMMARY_OPEN_ACTIONS-1];
411
412         NextUnreadMsgDialogShow next_unread_msg_dialog;
413         SummaryFromShow summary_from_show;
414         gboolean add_address_by_click;
415         gchar *pixmap_theme_path;
416 #ifdef HAVE_SVG
417         gboolean enable_alpha_svg;
418         gboolean enable_pixmap_scaling;
419         gboolean pixmap_scaling_auto;
420         gint pixmap_scaling_ppi;
421 #endif
422         int hover_timeout; /* msecs mouse hover timeout */
423         gboolean ask_mark_all_read;
424         gboolean run_processingrules_before_mark_all;
425         gboolean ask_override_colorlabel;
426         gboolean ask_apply_per_account_filtering_rules;
427         gint apply_per_account_filtering_rules;
428
429         /* Other */
430 #ifndef G_OS_WIN32
431         gchar *uri_cmd;
432 #else
433         gchar *gtk_theme;
434 #endif
435         gchar *ext_editor_cmd;
436         gboolean cmds_use_system_default;
437
438         gboolean cliplog;
439         guint loglength;
440         gboolean enable_log_standard;
441         gboolean enable_log_warning;
442         gboolean enable_log_error;
443         gboolean enable_log_status;
444
445         gboolean enable_filtering_debug;
446         gint filtering_debug_level;
447         gboolean enable_filtering_debug_inc;
448         gboolean enable_filtering_debug_manual;
449         gboolean enable_filtering_debug_folder_proc;
450         gboolean enable_filtering_debug_pre_proc;
451         gboolean enable_filtering_debug_post_proc;
452         gboolean filtering_debug_cliplog;
453         guint filtering_debug_loglength;
454
455         gboolean confirm_on_exit;
456         gboolean session_passwords;
457         gboolean clean_on_exit;
458         gboolean ask_on_clean;
459         gboolean warn_queued_on_exit;
460
461         gint io_timeout_secs;
462
463         gboolean gtk_can_change_accels;
464         gboolean gtk_enable_accels;
465         
466         /* Memory cache*/
467         gint cache_max_mem_usage;
468         gint cache_min_keep_time;
469         
470         /* boolean for work offline 
471            stored here for use in inc.c */
472         gboolean work_offline;
473         
474         gint summary_quicksearch_type;
475         gint summary_quicksearch_sticky;
476         gint summary_quicksearch_recurse;
477         gint summary_quicksearch_dynamic;
478         gint summary_quicksearch_autorun;
479
480         GList *summary_quicksearch_history;
481         GList *summary_search_from_history;
482         GList *summary_search_to_history;
483         GList *summary_search_subject_history;
484         GList *summary_search_body_history;
485         GList *summary_search_adv_condition_history;
486         GList *message_search_history;
487         GList *compose_save_to_history;
488
489         gint filteringwin_width;
490         gint filteringwin_height;
491         gint filteringactionwin_width;
492         gint filteringactionwin_height;
493         gint matcherwin_width;
494         gint matcherwin_height;
495         gint templateswin_width;
496         gint templateswin_height;
497         gint actionswin_width;
498         gint actionswin_height;
499         gint actionsiodialog_width;
500         gint actionsiodialog_height;
501         gint tagswin_width;
502         gint tagswin_height;
503         gint sslmanwin_width;
504         gint sslmanwin_height;
505         gint uriopenerwin_width;
506         gint uriopenerwin_height;
507         gint foldersortwin_width;
508         gint foldersortwin_height;
509         gint addressbookwin_width;
510         gint addressbookwin_height;
511         gint addressbookeditpersonwin_width;
512         gint addressbookeditpersonwin_height;
513         gint addressbookeditgroupwin_width;
514         gint addressbookeditgroupwin_height;
515         gint pluginswin_width;
516         gint pluginswin_height;
517         gint prefswin_width;
518         gint prefswin_height;
519         gint folderitemwin_width;
520         gint folderitemwin_height;
521         gchar *zero_replacement;
522         gint editaccountwin_width;
523         gint editaccountwin_height;
524         gint accountswin_width;
525         gint accountswin_height;
526         gint logwin_width;
527         gint logwin_height;
528         gint filtering_debugwin_width;
529         gint filtering_debugwin_height;
530         gint folderselwin_width;
531         gint folderselwin_height;
532         gint addressaddwin_width;
533         gint addressaddwin_height;
534         gint addressbook_folderselwin_width;
535         gint addressbook_folderselwin_height;
536         gint aboutwin_width;
537         gint aboutwin_height;
538         gint addrgather_width;
539         gint addrgather_height;
540         gint news_subscribe_width;
541         gint news_subscribe_height;
542
543     gint imap_scan_tree_recurs_limit;
544         gint warn_dnd;
545         gint broken_are_utf8;
546         gint skip_ssl_cert_check;
547         gint live_dangerously;
548         gint save_parts_readwrite;
549         gint never_send_retrcpt;
550         gint hide_quotes;
551         gboolean unsafe_ssl_certs;
552         gboolean real_time_sync;
553         
554         gchar *print_paper_type;
555         gint print_paper_orientation;
556         gint print_margin_top;
557         gint print_margin_bottom;
558         gint print_margin_left;
559         gint print_margin_right;
560   
561         gint print_use_color;
562         gint print_use_collate;
563         gint print_use_reverse;
564         gint print_use_duplex;
565         gint print_imgs;
566         gint print_previewwin_width;
567         gint print_previewwin_height;
568         
569         gboolean use_networkmanager;
570         gboolean use_shred;
571         gboolean two_line_vert;
572         gboolean inherit_folder_props;
573         gboolean flush_metadata;
574
575         gint nav_history_length;
576
577         gboolean folder_search_wildcard;
578         gboolean address_search_wildcard;
579
580         guint enable_avatars;
581
582 #ifndef PASSWORD_CRYPTO_OLD
583         gboolean use_master_passphrase;
584         gchar *master_passphrase;
585         gchar *master_passphrase_salt;
586         guint master_passphrase_pbkdf2_rounds;
587 #endif
588
589         /* Proxy */
590         gboolean use_proxy;
591         ProxyInfo proxy_info;
592 };
593
594 extern PrefsCommon prefs_common;
595
596 PrefsCommon *prefs_common_get_prefs(void);
597
598 GList *prefs_common_read_history_from_dir_with_defaults(const gchar *dirname, const gchar *history,
599                                                                                                                           GList *default_list);
600 void prefs_common_read_config   (void);
601 void prefs_common_write_config  (void);
602 void prefs_common_open          (void);
603 void pref_get_unescaped_pref(gchar *out, const gchar *in);
604 void pref_get_escaped_pref(gchar *out, const gchar *in);
605 void pref_set_textview_from_pref(GtkTextView *textview, const gchar *txt);
606 void pref_set_entry_from_pref(GtkEntry *entry, const gchar *txt);
607 gchar *pref_get_pref_from_textview(GtkTextView *textview);
608 gchar *pref_get_pref_from_entry(GtkEntry *entry);
609 const gchar *prefs_common_translated_header_name(const gchar *header_name);
610 const gchar *prefs_common_get_uri_cmd(void);
611 const gchar *prefs_common_get_ext_editor_cmd(void);
612
613 #define OPEN_SELECTED(when) (prefs_common.always_show_msg || prefs_common.when)
614
615 #define OPEN_SELECTED_ON_FOLDER_OPEN OPEN_SELECTED(open_selected_on_folder_open)
616 #define OPEN_SELECTED_ON_SEARCH_RESULTS OPEN_SELECTED(open_selected_on_search_results)
617 #define OPEN_SELECTED_ON_PREVNEXT OPEN_SELECTED(open_selected_on_prevnext)
618 #define OPEN_SELECTED_ON_DELETEMOVE OPEN_SELECTED(open_selected_on_deletemove)
619 #define OPEN_SELECTED_ON_DIRECTIONAL OPEN_SELECTED(open_selected_on_directional)
620
621 #endif /* __PREFS_COMMON_H__ */