Updates and hotkey fixes.
[claws.git] / src / wizard.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2016 Colin Leroy <colin@colino.net>
4  * and the Claws Mail team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/gtk.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36
37 #include "utils.h"
38 #include "gtk/menu.h"
39 #include "plugin.h"
40 #include "account.h"
41 #include "prefs_account.h"
42 #include "mainwindow.h"
43 #include "stock_pixmap.h"
44 #include "setup.h"
45 #include "folder.h"
46 #include "alertpanel.h"
47 #include "filesel.h"
48 #ifdef USE_GNUTLS
49 #include "ssl.h"
50 #endif
51 #include "prefs_common.h"
52 #include "combobox.h"
53 #include "passwordstore.h"
54
55 typedef enum
56 {
57         GO_BACK,
58         GO_FORWARD,
59         CANCEL,
60         FINISHED
61 } PageNavigation;
62
63 int WELCOME_PAGE = -1;
64 int USER_PAGE = -1;
65 int SMTP_PAGE = -1;
66 int RECV_PAGE = -1;
67 int MAILBOX_PAGE = -1;
68 int DONE_PAGE = -1;
69
70 typedef struct
71 {
72         GtkWidget *window;
73         GSList    *pages;
74         GtkWidget *notebook;
75
76         MainWindow *mainwin;
77         
78         GtkWidget *email;
79         GtkWidget *full_name;
80         GtkWidget *organization;
81
82         GtkWidget *mailbox_name;
83         GtkWidget *mailbox_label;
84         
85         GtkWidget *smtp_server;
86         GtkWidget *smtp_auth;
87         GtkWidget *smtp_username;
88         GtkWidget *smtp_password;
89         GtkWidget *smtp_username_label;
90         GtkWidget *smtp_password_label;
91
92         GtkWidget *recv_type;
93         GtkWidget *recv_label;
94         GtkWidget *recv_server;
95         GtkWidget *recv_username;
96         GtkWidget *recv_password;
97         GtkWidget *recv_username_label;
98         GtkWidget *recv_password_label;
99         GtkWidget *recv_imap_label;
100         GtkWidget *recv_imap_subdir;
101         GtkWidget *subsonly_checkbtn;
102         GtkWidget *no_imap_warning;
103 #ifdef USE_GNUTLS
104         GtkWidget *smtp_use_ssl;
105         GtkWidget *recv_use_ssl;
106         GtkWidget *smtp_use_tls;
107         GtkWidget *recv_use_tls;
108         GtkWidget *smtp_ssl_cert_file;
109         GtkWidget *recv_ssl_cert_file;
110         GtkWidget *smtp_ssl_cert_pass;
111         GtkWidget *recv_ssl_cert_pass;
112         GtkWidget *smtp_cert_table;
113         GtkWidget *recv_cert_table;
114 #endif
115 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
116         GtkWidget *auto_configure_lbl;
117         GtkWidget *auto_configure_btn;
118         GtkWidget *auto_configure_cancel_btn;
119 #endif
120         gboolean create_mailbox;
121         gboolean finished;
122         gboolean result;
123
124 } WizardWindow;
125
126 typedef struct _AccountTemplate {
127         gchar *name;
128         gchar *domain;
129         gchar *email;
130         gchar *organization;
131         gchar *smtpserver;
132         gboolean smtpauth;
133         gchar *smtpuser;
134         gchar *smtppass;
135         RecvProtocol recvtype;
136         gchar *recvserver;
137         gchar *recvuser;
138         gchar *recvpass;
139         gchar *imapdir;
140         gboolean subsonly;
141         gchar *mboxfile;
142         gchar *mailbox;
143         gboolean smtpssl;
144         gboolean recvssl;
145         gchar *smtpssl_cert;
146         gchar *recvssl_cert;
147         gchar *smtpssl_cert_pass;
148         gchar *recvssl_cert_pass;
149 } AccountTemplate;
150
151 static AccountTemplate tmpl;
152
153 static PrefParam template_params[] = {
154         {"name", "$USERNAME",
155          &tmpl.name, P_STRING, NULL, NULL, NULL},
156         {"domain", "$DEFAULTDOMAIN",
157          &tmpl.domain, P_STRING, NULL, NULL, NULL},
158         {"email", "$NAME_MAIL@$DOMAIN",
159          &tmpl.email, P_STRING, NULL, NULL, NULL},
160         {"organization", "",
161          &tmpl.organization, P_STRING, NULL, NULL, NULL},
162         {"smtpserver", "smtp.$DOMAIN",
163          &tmpl.smtpserver, P_STRING, NULL, NULL, NULL},
164         {"smtpauth", "FALSE",
165          &tmpl.smtpauth, P_BOOL, NULL, NULL, NULL},
166         {"smtpuser", "",
167          &tmpl.smtpuser, P_STRING, NULL, NULL, NULL},
168         {"smtppass", "",
169          &tmpl.smtppass, P_STRING, NULL, NULL, NULL},
170         {"recvtype", A_POP3,
171          &tmpl.recvtype, P_INT, NULL, NULL, NULL},
172         {"recvserver", "pop.$DOMAIN",
173          &tmpl.recvserver, P_STRING, NULL, NULL, NULL},
174         {"recvuser", "$LOGIN",
175          &tmpl.recvuser, P_STRING, NULL, NULL, NULL},
176         {"recvpass", "",
177          &tmpl.recvpass, P_STRING, NULL, NULL, NULL},
178         {"imapdir", "",
179          &tmpl.imapdir, P_STRING, NULL, NULL, NULL},
180         {"subsonly", "TRUE",
181          &tmpl.subsonly, P_BOOL, NULL, NULL, NULL},
182         {"mboxfile", "/var/mail/$LOGIN",
183          &tmpl.mboxfile, P_STRING, NULL, NULL, NULL},
184         {"mailbox", "Mail",
185          &tmpl.mailbox, P_STRING, NULL, NULL, NULL},
186         {"smtpssl", "0",
187          &tmpl.smtpssl, P_INT, NULL, NULL, NULL},
188         {"recvssl", "0",
189          &tmpl.recvssl, P_INT, NULL, NULL, NULL},
190         {"smtpssl_cert", "",
191          &tmpl.smtpssl_cert, P_STRING, NULL, NULL, NULL},
192         {"recvssl_cert", "",
193          &tmpl.recvssl_cert, P_STRING, NULL, NULL, NULL},
194         {"smtpssl_cert_pass", "",
195          &tmpl.smtpssl_cert, P_STRING, NULL, NULL, NULL},
196         {"recvssl_cert_pass", "",
197          &tmpl.recvssl_cert, P_STRING, NULL, NULL, NULL},
198         {NULL, NULL, NULL, P_INT, NULL, NULL, NULL}
199 };
200
201
202 static gchar *accountrc_tmpl =
203         "[AccountTemplate]\n"
204         "#you can use $DEFAULTDOMAIN here\n"
205         "#domain must be defined before the variables that use it\n"
206         "#by default, domain is extracted from the hostname\n"
207         "#domain=\n"
208         "\n"
209         "#you can use $USERNAME for name (this is the default)\n"
210         "#name=\n"
211         "\n"
212         "#you can use $LOGIN, $NAME_MAIL and $DOMAIN here \n"
213         "#$NAME_MAIL is the name without uppercase and with dots instead\n"
214         "#of spaces\n"
215         "#the default is $NAME_MAIL@$DOMAIN\n"
216         "#email=\n"
217         "\n"
218         "#you can use $DOMAIN here\n"
219         "#the default organization is empty\n"
220         "#organization=\n"
221         "\n"
222         "#you can use $DOMAIN here \n"
223         "#the default is smtp.$DOMAIN\n"
224         "#smtpserver=\n"
225         "\n"
226         "#Whether to use smtp authentication\n"
227         "#the default is 0 (no)\n"
228         "#smtpauth=\n"
229         "\n"
230         "#SMTP username\n"
231         "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
232         "#the default is empty (same as reception username)\n"
233         "#smtpuser=\n"
234         "\n"
235         "#SMTP password\n"
236         "#the default is empty (same as reception password)\n"
237         "#smtppass=\n"
238         "\n"
239         "#recvtype can be:\n"
240         "#0 for pop3\n"
241         "#3  for imap\n"
242         "#5  for a local mbox file\n"
243         "#recvtype=\n"
244         "\n"
245         "#you can use $DOMAIN here \n"
246         "#the default is {pop,imap}.$DOMAIN\n"
247         "#recvserver=\n"
248         "\n"
249         "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
250         "#default is $LOGIN\n"
251         "#recvuser=\n"
252         "\n"
253         "#default is empty\n"
254         "#recvpass=\n"
255         "\n"
256         "#imap dir if imap (relative to the home on the server)\n"
257         "#default is empty\n"
258         "#imapdir=\n"
259         "\n"
260         "#show subscribed folders only, if imap\n"
261         "#default is TRUE\n"
262         "#subsonly=\n"
263         "\n"
264         "#mbox file if local\n"
265         "#you can use $LOGIN here\n"
266         "#default is /var/mail/$LOGIN\n"
267         "#mboxfile=\n"
268         "\n"
269         "#mailbox name if pop3 or local\n"
270         "#relative path from the user's home\n"
271         "#default is \"Mail\"\n"
272         "#mailbox=\n"
273         "\n"
274         "#whether to use encryption on SMTP connections\n"
275         "#default is 0, 1 is SSL/TLS, 2 is STARTTLS\n"
276         "#smtpssl=\n"
277         "\n"
278         "#whether to use encryption on POP3 or IMAP connections\n"
279         "#default is 0, 1 is SSL/TLS, 2 is STARTTLS\n"
280         "#recvssl=\n"
281         "\n"
282         "#SSL/TLS client certificate path for SMTP\n"
283         "#default is empty (no certificate)\n"
284         "#smtpssl_cert=\n"
285         "\n"
286         "#SSL/TLS client certificate path for POP/IMAP\n"
287         "#default is empty (no certificate)\n"
288         "#recvssl_cert=\n"
289         "\n"
290         "#SSL/TLS client certificate password for SMTP\n"
291         "#default is empty (no password)\n"
292         "#smtpssl_cert_pass=\n"
293         "\n"
294         "#SSL/TLS client certificate password for POP/IMAP\n"
295         "#default is empty (no password)\n"
296         "#recvssl_cert_pass=\n"
297         ;
298
299 static gchar *wizard_get_default_domain_name(void)
300 {
301         static gchar *domain_name = NULL;
302         
303         if (domain_name == NULL) {
304                 domain_name = g_strdup(get_domain_name());
305                 if (strchr(domain_name, '.') != NULL 
306                 && strchr(domain_name, '.') != strrchr(domain_name, '.')
307                 && strlen(strchr(domain_name, '.')) > 6) {
308                         gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
309                         g_free(domain_name);
310                         domain_name = tmp;
311                 }
312         }
313         return domain_name;
314 }
315
316 static gchar *get_name_for_mail(void)
317 {
318         gchar *name = NULL;
319         if (tmpl.name == NULL)
320                 return NULL;
321         name = g_utf8_strdown(tmpl.name, -1);
322         while(strstr(name, " "))
323                 *strstr(name, " ")='.';
324         
325         return name;
326 }
327
328 #define PARSE_DEFAULT(str) {    \
329         gchar *tmp = NULL, *new = NULL; \
330         if (str != NULL) {      \
331                 if (strstr(str, "$USERNAME")) { \
332                         tmp = g_strdup(str); \
333                         *strstr(tmp, "$USERNAME") = '\0';       \
334                         new = g_strconcat(tmp, g_get_real_name(),       \
335                                 strstr(str, "$USERNAME")+strlen("$USERNAME"),   \
336                                 NULL);  \
337                         g_free(tmp);    \
338                         g_free(str);    \
339                         str = new;      \
340                         new = NULL;     \
341                 }       \
342                 if (strstr(str, "$LOGIN")) {    \
343                         tmp = g_strdup(str); \
344                         *strstr(tmp, "$LOGIN") = '\0';  \
345                         new = g_strconcat(tmp, g_get_user_name(),       \
346                                 strstr(str, "$LOGIN")+strlen("$LOGIN"),         \
347                                 NULL);  \
348                         g_free(tmp);    \
349                         g_free(str);    \
350                         str = new;      \
351                         new = NULL;     \
352                 }       \
353                 if (strstr(str, "$EMAIL")) {    \
354                         tmp = g_strdup(str); \
355                         *strstr(tmp, "$EMAIL") = '\0';  \
356                         new = g_strconcat(tmp, tmpl.email,      \
357                                 strstr(str, "$EMAIL")+strlen("$EMAIL"),         \
358                                 NULL);  \
359                         g_free(tmp);    \
360                         g_free(str);    \
361                         str = new;      \
362                         new = NULL;     \
363                 }       \
364                 if (strstr(str, "$NAME_MAIL")) {        \
365                         tmp = g_strdup(str); \
366                         *strstr(tmp, "$NAME_MAIL") = '\0';      \
367                         new = g_strconcat(tmp, get_name_for_mail(),     \
368                                 strstr(str, "$NAME_MAIL")+strlen("$NAME_MAIL"),         \
369                                 NULL);  \
370                         g_free(tmp);    \
371                         g_free(str);    \
372                         str = new;      \
373                         new = NULL;     \
374                 }       \
375                 if (strstr(str, "$DEFAULTDOMAIN")) {    \
376                         tmp = g_strdup(str); \
377                         *strstr(tmp, "$DEFAULTDOMAIN") = '\0';  \
378                         new = g_strconcat(tmp, wizard_get_default_domain_name(),        \
379                                 strstr(str, "$DEFAULTDOMAIN")+strlen("$DEFAULTDOMAIN"),         \
380                                 NULL);  \
381                         g_free(tmp);    \
382                         g_free(str);    \
383                         str = new;      \
384                         new = NULL;     \
385                 }       \
386                 if (strstr(str, "$DOMAIN")) {   \
387                         tmp = g_strdup(str); \
388                         *strstr(tmp, "$DOMAIN") = '\0'; \
389                         new = g_strconcat(tmp, tmpl.domain,     \
390                                 strstr(str, "$DOMAIN")+strlen("$DOMAIN"),       \
391                                 NULL);  \
392                         g_free(tmp);    \
393                         g_free(str);    \
394                         str = new;      \
395                         new = NULL;     \
396                 }       \
397         }       \
398 }
399 static void wizard_read_defaults(void)
400 {
401         gchar *rcpath;
402
403         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "accountrc.tmpl", NULL);
404         if (!is_file_exist(rcpath)) {
405                 str_write_to_file(accountrc_tmpl, rcpath);
406         }
407
408         prefs_read_config(template_params, "AccountTemplate", rcpath, NULL);
409
410         PARSE_DEFAULT(tmpl.domain);
411         PARSE_DEFAULT(tmpl.name);
412         PARSE_DEFAULT(tmpl.email);
413         PARSE_DEFAULT(tmpl.organization);
414         PARSE_DEFAULT(tmpl.smtpserver);
415         PARSE_DEFAULT(tmpl.smtpuser);
416         PARSE_DEFAULT(tmpl.smtppass);
417         PARSE_DEFAULT(tmpl.recvserver);
418         PARSE_DEFAULT(tmpl.recvuser);
419         PARSE_DEFAULT(tmpl.recvpass);
420         PARSE_DEFAULT(tmpl.imapdir);
421         PARSE_DEFAULT(tmpl.mboxfile);
422         PARSE_DEFAULT(tmpl.mailbox);
423 /*
424         g_print("defaults:"
425         "%s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s, %s, %d, %d\n",
426         tmpl.name,tmpl.domain,tmpl.email,tmpl.organization,tmpl.smtpserver,
427         tmpl.recvtype,tmpl.recvserver,tmpl.recvuser,tmpl.recvpass,
428         tmpl.imapdir,tmpl.mboxfile,tmpl.mailbox,tmpl.smtpssl,tmpl.recvssl);
429 */
430         g_free(rcpath);
431 }
432
433 static void initialize_fonts(WizardWindow *wizard)
434 {
435         GtkWidget *widget = wizard->email;
436         gint size = pango_font_description_get_size(
437                         gtk_widget_get_style(widget)->font_desc)
438                       /PANGO_SCALE;
439         gchar *tmp, *new;
440 #ifdef G_OS_WIN32
441         PangoFontDescription *bold_desc;
442         gchar *curfont = pango_font_description_to_string(widget->style->font_desc);
443         g_free(prefs_common.smallfont);
444         g_free(prefs_common.normalfont);
445         g_free(prefs_common.boldfont);
446         prefs_common.smallfont = g_strdup(curfont);
447         prefs_common.normalfont = g_strdup(curfont);
448         bold_desc = pango_font_description_from_string(curfont);
449         pango_font_description_set_weight(bold_desc, PANGO_WEIGHT_BOLD);
450         prefs_common.boldfont = pango_font_description_to_string(bold_desc);
451         pango_font_description_free(bold_desc);
452         g_free(curfont);
453 #endif  
454         tmp = g_strdup(prefs_common.textfont);
455         if (strrchr(tmp, ' ')) {
456                 *(strrchr(tmp, ' ')) = '\0';
457                 new = g_strdup_printf("%s %d", tmp, size);
458                 g_free(prefs_common.textfont);
459                 prefs_common.textfont = new;
460         }
461         g_free(tmp);
462         
463         tmp = g_strdup(prefs_common.smallfont);
464         if (strrchr(tmp, ' ')) {
465                 *(strrchr(tmp, ' ')) = '\0';
466                 new = g_strdup_printf("%s %d", tmp, size);
467                 g_free(prefs_common.smallfont);
468                 prefs_common.smallfont = new;
469         }
470         g_free(tmp);
471         
472         tmp = g_strdup(prefs_common.normalfont);
473         if (strrchr(tmp, ' ')) {
474                 *(strrchr(tmp, ' ')) = '\0';
475                 new = g_strdup_printf("%s %d", tmp, size);
476                 g_free(prefs_common.normalfont);
477                 prefs_common.normalfont = new;
478         }
479         g_free(tmp);
480
481         tmp = g_strdup(prefs_common.boldfont);
482         if (strrchr(tmp, ' ')) {
483                 *(strrchr(tmp, ' ')) = '\0';
484                 new = g_strdup_printf("%s %d", tmp, size);
485                 g_free(prefs_common.boldfont);
486                 prefs_common.boldfont = new;
487         }
488         g_free(tmp);
489 }
490
491 #define XFACE "+}Axz@~a,-Yx?0Ysa|q}CLRH=89Y]\"')DSX^<6p\"d)'81yx5%G#u^o*7JG&[aPU0h1Ux.vb2yIjH83{5`/bVo|~nn/i83vE^E)qk-4W)_E.4Y=D*qvf/,Ci_=P<iY<M6"
492 #define FACE "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAM1BMVEUAAAAcJCI\n\
493  ONl1JUi0+Z4daY2NZciPabV9ykS5kj6Wsl2ybmZOBsMjZxK2wzN3Pzczs7OsCAGN0AAAAAXRSTlM\n\
494  AQObYZgAAAAFiS0dEAIgFHUgAAAIVSURBVEjH1ZbtlqMgDIaFECoGhPu/2s0b0Lais/NzN6d1OJ7\n\
495  3yReQzrL8B5Zy3rvl9At52Pf2tv1vSMjtYj8jaa8XUyI/yn3YD6sigj/2Tf5Bn069MIsTPHvx/t5\n\
496  /3rU/6JCIY3YwGe26r/cwUfE3cFe5T28L0K5rJAUHEeYAQxs8DHojjk3M9wECU4xxjXisI8RA0gy\n\
497  oczJZJOjxiTFZVTchAnIRJrgdmEGDyFfAI3UuG5FmYTkR9RDrIC4H0SqV4pzpEcUp0HNLjwBv+jA\n\
498  dikUE5g9iBvzmu3sH2oDk4lnHd829+2Q9gj6kDqDPg7hsGwBzH02fE3ZCt6ZHmlNKIMjMeRwra5I\n\
499  ecgNoBnLGPmzaHPJIwLY8Sq2M/tLUJfj0QcqmfVXAdLSStIYF8dzWjBBb2VgvDa4mO9oc651OiUo\n\
500  BEKbZokdPATF9E9oKAjQJcJOniaPXrVZRAnVWaqIyqRoNC8ZJvgCcW8XN39RqxVP1rS8Yd4WnCdN\n\
501  aRTo2jJRDbg3vtCpEUGffgDPhqKDaSuVqYtOplFIvIcx3HUI5/MuIWl6vKyBjNlqEru8hbFXqBPA\n\
502  5TpHGIUZOePeaIyzfQ/g9Xg0opU1AvdfXM9floYhv92pPAE96OZtkPV8eivgQi9RTfwPUU36I26n\n\
503  Hy+WuCJzAT7efMSeA1TNf2/VugDz+dN139xfA5ffxGZDD+MvcP/uvyB80wzZ76wbz8gAAAABJRU5\n\
504  ErkJggg=="
505
506 static void write_welcome_email(WizardWindow *wizard)
507 {
508         gchar buf_date[64];
509         gchar *head=NULL;
510         gchar *body=NULL;
511         gchar *msg=NULL;
512         const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name));
513         Folder *folder = folder_find_from_path(mailbox);
514         FolderItem *inbox = folder ? folder->inbox:NULL;
515         gchar *file = get_tmp_file();
516         gchar enc_from_name[BUFFSIZE], enc_to_name[BUFFSIZE], enc_subject[BUFFSIZE];
517         
518         get_rfc822_date(buf_date, sizeof(buf_date));
519
520         conv_encode_header_full(enc_subject, sizeof(enc_subject), 
521                         C_("Welcome Mail Subject", "Welcome to Claws Mail"),
522                         strlen("Subject: "), FALSE, CS_INTERNAL);
523         conv_encode_header_full(enc_to_name, sizeof(enc_to_name), 
524                         gtk_entry_get_text(GTK_ENTRY(wizard->full_name)),
525                         strlen("To: "), TRUE, CS_INTERNAL);
526         conv_encode_header_full(enc_from_name, sizeof(enc_from_name), 
527                         _("The Claws Mail Team"),
528                         strlen("From: "), TRUE, CS_INTERNAL);
529
530         head = g_strdup_printf(
531                 "From: %s <%s>\n"
532                 "To: %s <%s>\n"
533                 "Date: %s\n"
534                 "Subject: %s\n"
535                 "X-Face: %s\n"
536                 "Face: %s\n"
537                 "Content-Type: text/plain; charset=UTF-8\n",
538                 enc_from_name,
539                 USERS_ML_ADDR,
540                 enc_to_name,
541                 gtk_entry_get_text(GTK_ENTRY(wizard->email)),
542                 buf_date, enc_subject, XFACE, FACE);
543         body = g_strdup_printf(
544                 _("\n"
545                 "Welcome to Claws Mail\n"
546                 "---------------------\n"
547                 "\n"
548                 "Now that you have set up your account you can fetch your\n"
549                 "mail by clicking the 'Get Mail' button at the left of the\n"
550                 "toolbar.\n"
551                 "\n"
552                 "Claws Mail has lots of extra features accessible via plugins,\n"
553                 "like anti-spam filtering and learning (via the Bogofilter or\n"
554                 "SpamAssassin plugins), privacy protection (via PGP/Mime), an RSS\n"
555                 "aggregator, a calendar, and much more. You can load them from\n"
556                 "the menu entry '/Configuration/Plugins'.\n"
557                 "\n"
558                 "You can change your Account Preferences by using the menu\n"
559                 "entry '/Configuration/Preferences for current account'\n"
560                 "and change the general Preferences by using\n"
561                 "'/Configuration/Preferences'.\n"
562                 "\n"
563                 "You can find further information in the Claws Mail manual,\n"
564                 "which can be accessed by using the menu entry '/Help/Manual'\n"
565                 "or online at the URL given below.\n"
566                 "\n"
567                 "Useful URLs\n"
568                 "-----------\n"
569                 "Homepage:      <%s>\n"
570                 "Manual:        <%s>\n"
571                 "FAQ:           <%s>\n"
572                 "Themes:        <%s>\n"
573                 "Mailing Lists: <%s>\n"
574                 "\n"
575                 "LICENSE\n"
576                 "-------\n"
577                 "Claws Mail is free software, released under the terms\n"
578                 "of the GNU General Public License, version 3 or later, as\n"
579                 "published by the Free Software Foundation. The license can\n"
580                 "be found at <%s>.\n"
581                 "\n"
582                 "DONATIONS\n"
583                 "---------\n"
584                 "If you wish to donate to the Claws Mail project you can do\n"
585                 "so at <%s>.\n\n"),
586                 HOMEPAGE_URI, MANUAL_URI, FAQ_URI, THEMES_URI, MAILING_LIST_URI,
587                 GPL_URI, DONATE_URI);
588         
589         msg = g_strconcat(head, body, NULL);
590
591         if (inbox && inbox->total_msgs == 0
592          && str_write_to_file(msg, file) >= 0) {
593                 MsgFlags flags = { MSG_UNREAD|MSG_NEW, 0};
594                 folder_item_add_msg(inbox, file, &flags, FALSE);
595         }
596         g_free(head);
597         g_free(body);
598         g_free(msg);
599         claws_unlink(file);
600 }
601 #undef XFACE
602
603 static gboolean wizard_write_config(WizardWindow *wizard)
604 {
605         static gboolean mailbox_ok = FALSE;
606         PrefsAccount *prefs_account = prefs_account_new();
607         GList *account_list = NULL;
608         gchar *smtp_server, *recv_server;
609         gint smtp_port, recv_port;
610 #ifdef USE_GNUTLS
611         SSLType smtp_ssl_type, recv_ssl_type;
612 #endif
613
614         prefs_account->protocol = combobox_get_active_data(
615                                         GTK_COMBO_BOX(wizard->recv_type));
616         
617         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4 && 
618             !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)))) {
619                 alertpanel_error(_("Please enter the mailbox name."));
620                 g_free(prefs_account);
621                 gtk_notebook_set_current_page (
622                         GTK_NOTEBOOK(wizard->notebook), 
623                         MAILBOX_PAGE);
624                 return FALSE;
625         }
626
627         if (!mailbox_ok) {
628                 if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
629                         mailbox_ok = setup_write_mailbox_path(wizard->mainwin, 
630                                         gtk_entry_get_text(
631                                                 GTK_ENTRY(wizard->mailbox_name)));
632                 } else
633                         mailbox_ok = TRUE;
634         }
635
636         if (!mailbox_ok) {
637                 /* alertpanel done by setup_write_mailbox_path */
638                 g_free(prefs_account);
639                 gtk_notebook_set_current_page (
640                         GTK_NOTEBOOK(wizard->notebook), 
641                         MAILBOX_PAGE);
642                 return FALSE;
643         }
644         
645         if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->full_name)))
646         ||  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->email)))) {
647                 alertpanel_error(_("Please enter your name and email address."));
648                 g_free(prefs_account);
649                 gtk_notebook_set_current_page (
650                         GTK_NOTEBOOK(wizard->notebook), 
651                         USER_PAGE);
652                 return FALSE;
653         }
654         
655         if (prefs_account->protocol != A_LOCAL) {
656                 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)))
657                 ||  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
658                         alertpanel_error(_("Please enter your receiving server "
659                                            "and username."));
660                         g_free(prefs_account);
661                         gtk_notebook_set_current_page (
662                                 GTK_NOTEBOOK(wizard->notebook), 
663                                 RECV_PAGE);
664                         return FALSE;
665                 }
666         } else {
667                 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
668                         alertpanel_error(_("Please enter your username."));
669                         g_free(prefs_account);
670                         gtk_notebook_set_current_page (
671                                 GTK_NOTEBOOK(wizard->notebook), 
672                                 RECV_PAGE);
673                         return FALSE;
674                 }
675         }
676         
677         if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)))) {
678                 alertpanel_error(_("Please enter your SMTP server."));
679                 g_free(prefs_account);
680                 gtk_notebook_set_current_page (
681                         GTK_NOTEBOOK(wizard->notebook), 
682                         SMTP_PAGE);
683                 return FALSE;
684         }
685
686         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
687                 if (prefs_account->protocol == A_LOCAL
688                 &&  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)))) {
689                         alertpanel_error(_("Please enter your SMTP username."));
690                         g_free(prefs_account);
691                         gtk_notebook_set_current_page (
692                                 GTK_NOTEBOOK(wizard->notebook), 
693                                 SMTP_PAGE);
694                         return FALSE;           
695                 } /* if it's not local we'll use the reception server */
696         }
697
698         if (prefs_account->protocol != A_LOCAL)
699                 prefs_account->account_name = g_strdup_printf("%s@%s",
700                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
701                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
702         else
703                 prefs_account->account_name = g_strdup_printf("%s",
704                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
705
706         recv_server = g_strdup(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
707         smtp_server = g_strdup(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)));
708
709         if (prefs_account->protocol != A_LOCAL && strstr(recv_server, ":")) {
710                 recv_port = atoi(strstr(recv_server, ":")+1);
711                 *(strstr(recv_server, ":")) = '\0';
712                 if (prefs_account->protocol == A_IMAP4) {
713                         prefs_account->set_imapport = TRUE;
714                         prefs_account->imapport = recv_port;
715                 } else if (prefs_account->protocol == A_POP3) {
716                         prefs_account->set_popport = TRUE;
717                         prefs_account->popport = recv_port;
718                 }
719         }
720         if (strstr(smtp_server, ":")) {
721                 smtp_port = atoi(strstr(smtp_server, ":")+1);
722                 *(strstr(smtp_server, ":")) = '\0';
723                 prefs_account->set_smtpport = TRUE;
724                 prefs_account->smtpport = smtp_port;
725         }
726         
727         prefs_account->name = g_strdup(
728                                 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)));
729         prefs_account->address = g_strdup(
730                                 gtk_entry_get_text(GTK_ENTRY(wizard->email)));
731         prefs_account->organization = g_strdup(
732                                 gtk_entry_get_text(GTK_ENTRY(wizard->organization)));
733         prefs_account->smtp_server = g_strdup(smtp_server);
734
735         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
736                 gchar *tmp;
737                 tmp = g_path_get_basename(gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)));
738                 prefs_account->inbox = g_strdup_printf("#mh/%s/inbox",
739                         (!strcmp("Mail", gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name))))
740                                 ?_("Mailbox"):tmp);
741                 g_free(tmp);
742                 prefs_account->local_inbox = g_strdup(prefs_account->inbox);
743         } else if (prefs_account->protocol != A_IMAP4) {
744                 if (folder_get_default_inbox())
745                         prefs_account->local_inbox = 
746                                 folder_item_get_identifier(folder_get_default_inbox());
747         }
748
749         if (prefs_account->protocol != A_LOCAL)
750                 prefs_account->recv_server = g_strdup(recv_server);
751         else
752                 prefs_account->local_mbox = g_strdup(recv_server);
753
754         g_free(recv_server);
755         g_free(smtp_server);
756
757         prefs_account->userid = g_strdup(
758                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
759         prefs_account->smtp_userid = g_strdup(
760                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)));
761
762         passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_RECV,
763                         gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)),
764                         FALSE);
765         passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_SEND,
766                         gtk_entry_get_text(GTK_ENTRY(wizard->smtp_password)),
767                         FALSE);
768
769         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
770                 prefs_account->use_smtp_auth = TRUE;
771         }
772
773 #ifdef USE_GNUTLS
774         smtp_ssl_type = SSL_NONE;
775         recv_ssl_type = SSL_NONE;       
776
777         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl))) {
778                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls)))
779                         smtp_ssl_type = SSL_STARTTLS;
780                 else
781                         smtp_ssl_type = SSL_TUNNEL;
782         }
783         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
784                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls)))
785                         recv_ssl_type = SSL_STARTTLS;
786                 else
787                         recv_ssl_type = SSL_TUNNEL;
788         }
789
790         prefs_account->ssl_smtp = smtp_ssl_type;
791
792         if (prefs_account->protocol == A_IMAP4)
793                 prefs_account->ssl_imap = recv_ssl_type;
794         else
795                 prefs_account->ssl_pop = recv_ssl_type;
796
797         prefs_account->out_ssl_client_cert_file = g_strdup(
798                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_ssl_cert_file)));
799         prefs_account->in_ssl_client_cert_file = g_strdup(
800                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_ssl_cert_file)));
801
802         passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_SEND_CERT,
803                         gtk_entry_get_text(GTK_ENTRY(wizard->smtp_ssl_cert_pass)),
804                         FALSE);
805         passwd_store_set_account(prefs_account->account_id, PWS_ACCOUNT_RECV_CERT,
806                         gtk_entry_get_text(GTK_ENTRY(wizard->recv_ssl_cert_pass)),
807                         FALSE);
808 #endif
809
810         if (prefs_account->protocol == A_IMAP4) {
811                 gchar *directory = gtk_editable_get_chars(
812                         GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
813                 if (directory && strlen(directory)) {
814                         prefs_account->imap_dir = g_strdup(directory);
815                 }
816                 prefs_account->imap_subsonly = 
817                         gtk_toggle_button_get_active(
818                                 GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn));
819                 g_free(directory);
820         }
821
822         account_list = g_list_append(account_list, prefs_account);
823         prefs_account_write_config_all(account_list);
824         prefs_account_free(prefs_account);
825         account_read_config_all();
826
827         initialize_fonts(wizard);
828         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4)
829                 write_welcome_email(wizard);
830
831 #ifndef G_OS_WIN32 
832         plugin_load_standard_plugins();
833 #endif
834         return TRUE;
835 }
836
837 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
838 {
839         GtkWidget *w;
840         GtkWidget *vbox;
841         GtkWidget *hbox;
842         GtkWidget *image;
843         char *title_string;
844
845         vbox = gtk_vbox_new (FALSE, 6);
846         gtk_container_set_border_width  (GTK_CONTAINER(vbox), 10);
847
848         /* create the titlebar */
849         hbox = gtk_hbox_new (FALSE, 12);
850         image = stock_pixmap_widget(STOCK_PIXMAP_CLAWS_MAIL_ICON);
851         gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
852         title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
853         w = gtk_label_new (title_string);
854         gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
855         g_free (title_string);
856         gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
857
858         /* pack the titlebar */
859         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
860
861         /* pack the separator */
862         gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
863
864         /* pack space */
865         w = gtk_alignment_new (0, 0, 0, 0);
866         gtk_widget_set_size_request (w, 0, 6);
867         gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
868
869         return vbox;
870 }
871
872 #define PACK_BOX(hbox,text,entry) {                                     \
873         GtkWidget *label = gtk_label_new(text);                         \
874         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);               \
875         if (GTK_IS_MISC(label))                                         \
876                 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);        \
877         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);      \
878         gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);        \
879 }
880
881 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
882 {
883         if (!strcmp(type, "smtp")) {
884                 if (!tmpl.smtpserver || !strlen(tmpl.smtpserver))
885                         return g_strconcat(type, ".", tmpl.domain, NULL);
886                 else 
887                         return g_strdup(tmpl.smtpserver);
888         } else {
889                 if (!tmpl.recvserver || !strlen(tmpl.recvserver))
890                         return g_strconcat(type, ".", tmpl.domain, NULL);
891                 else 
892                         return g_strdup(tmpl.recvserver);
893         }
894 }
895
896 static gchar *get_default_account(WizardWindow * wizard)
897 {
898         gchar *result = NULL;
899         
900         if (!tmpl.recvuser || !strlen(tmpl.recvuser)) {
901                 result = gtk_editable_get_chars(
902                                 GTK_EDITABLE(wizard->email), 0, -1);
903
904                 if (strstr(result, "@")) {
905                         *(strstr(result,"@")) = '\0';
906                 } 
907         } else {
908                 result = g_strdup(tmpl.recvuser);
909         }
910         return result;
911 }
912
913 static gchar *get_default_smtp_account(WizardWindow * wizard)
914 {
915         gchar *result = NULL;
916         
917         if (!tmpl.smtpuser || !strlen(tmpl.smtpuser)) {
918                 return g_strdup("");
919         } else {
920                 result = g_strdup(tmpl.smtpuser);
921         }
922         return result;
923 }
924
925 static void wizard_email_changed(GtkWidget *widget, gpointer data)
926 {
927         WizardWindow *wizard = (WizardWindow *)data;
928         RecvProtocol protocol;
929         gchar *text;
930         protocol = combobox_get_active_data(GTK_COMBO_BOX(wizard->recv_type));
931         
932         text = get_default_server(wizard, "smtp");
933         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
934         g_free(text);
935
936         text = get_default_account(wizard);
937         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
938         g_free(text);
939
940         if (protocol == A_POP3) {
941                 text = get_default_server(wizard, "pop");
942                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
943                 g_free(text);
944         } else if (protocol == A_IMAP4) {
945                 text = get_default_server(wizard, "imap");
946                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
947                 g_free(text);
948         } else if (protocol == A_LOCAL) {
949                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
950         }
951         
952 }
953
954 static GtkWidget* user_page (WizardWindow * wizard)
955 {
956         GtkWidget *table = gtk_table_new(1,1, FALSE);
957         GtkWidget *vbox;
958         GtkWidget *label;
959         GtkWidget *user_table;
960         
961         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
962         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
963
964         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
965         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
966
967         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
968                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
969
970         user_table = gtk_table_new(3, 2, FALSE);
971         gtk_table_set_row_spacings(GTK_TABLE(user_table), VSPACING_NARROW);
972         gtk_box_pack_start(GTK_BOX(vbox), user_table, FALSE, FALSE, 0);
973
974         label = gtk_label_new(g_strconcat("<span weight=\"bold\">", _("Your name:"),
975                                           "</span>", NULL));
976         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
977         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
978         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,0,1, 
979                          GTK_FILL, 0, VSPACING_NARROW, 0);
980         wizard->full_name = gtk_entry_new();
981         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), tmpl.name?tmpl.name:"");
982         gtk_table_attach(GTK_TABLE(user_table), wizard->full_name, 1,2,0,1, 
983                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
984
985         label = gtk_label_new(g_strconcat("<span weight=\"bold\">", _("Your email address:"),
986                                           "</span>", NULL));
987         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
988         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
989         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,1,2, 
990                          GTK_FILL, 0, VSPACING_NARROW, 0);
991         wizard->email = gtk_entry_new();
992         gtk_entry_set_text(GTK_ENTRY(wizard->email), tmpl.email?tmpl.email:"");
993         gtk_table_attach(GTK_TABLE(user_table), wizard->email, 1,2,1,2, 
994                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
995
996         label = gtk_label_new(_("Your organization:"));
997         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
998         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,2,3, 
999                          GTK_FILL, 0, VSPACING_NARROW, 0);
1000         wizard->organization = gtk_entry_new();
1001         gtk_entry_set_text(GTK_ENTRY(wizard->organization), tmpl.organization?tmpl.organization:"");
1002         gtk_table_attach(GTK_TABLE(user_table), wizard->organization, 1,2,2,3, 
1003                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1004         
1005         g_signal_connect(G_OBJECT(wizard->email), "changed",
1006                          G_CALLBACK(wizard_email_changed),
1007                          wizard);
1008         return table;
1009 }
1010
1011 static GtkWidget* mailbox_page (WizardWindow * wizard)
1012 {
1013         GtkWidget *table = gtk_table_new(1,1, FALSE);
1014         GtkWidget *vbox;
1015         GtkWidget *hbox;
1016
1017         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1018         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1019
1020         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1021         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1022
1023         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1024                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1025
1026         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1027         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1028
1029         wizard->mailbox_label = gtk_label_new(g_strconcat("<span weight=\"bold\">",
1030                                                           _("Mailbox name:"), "</span>", NULL));
1031         gtk_label_set_use_markup(GTK_LABEL(wizard->mailbox_label), TRUE);
1032         if (GTK_IS_MISC(wizard->mailbox_label))                                               
1033                 gtk_misc_set_alignment(GTK_MISC(wizard->mailbox_label), 1, 0.5);              
1034         wizard->mailbox_name = gtk_entry_new();
1035
1036         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), tmpl.mailbox?tmpl.mailbox:"");
1037
1038         CLAWS_SET_TIP(wizard->mailbox_name, _("You can also specify an absolute path, for example: "
1039                                "\"/home/john/Documents/Mail\""));
1040
1041         gtk_box_pack_start(GTK_BOX(hbox), wizard->mailbox_label, FALSE, FALSE, 0);
1042         gtk_box_pack_start(GTK_BOX(hbox), wizard->mailbox_name, TRUE, TRUE, 0);
1043
1044         return table;
1045 }
1046
1047 static void smtp_auth_changed (GtkWidget *btn, gpointer data)
1048 {
1049         WizardWindow *wizard = (WizardWindow *)data;
1050         gboolean do_auth = gtk_toggle_button_get_active(
1051                 GTK_TOGGLE_BUTTON(wizard->smtp_auth));
1052         gtk_widget_set_sensitive(wizard->smtp_username, do_auth);
1053         gtk_widget_set_sensitive(wizard->smtp_username_label, do_auth);
1054         gtk_widget_set_sensitive(wizard->smtp_password, do_auth);
1055         gtk_widget_set_sensitive(wizard->smtp_password_label, do_auth);
1056 }
1057
1058 #ifdef USE_GNUTLS
1059 static void cert_browse_cb(GtkWidget *widget, gpointer data)
1060 {
1061         GtkEntry *dest = GTK_ENTRY(data);
1062         gchar *filename;
1063         gchar *utf8_filename;
1064
1065         filename = filesel_select_file_open(_("Select certificate file"), NULL);
1066         if (!filename) return;
1067
1068         utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
1069         if (!utf8_filename) {
1070                 g_warning("cert_browse_cb(): failed to convert character set.");
1071                 utf8_filename = g_strdup(filename);
1072         }
1073         gtk_entry_set_text(dest, utf8_filename);
1074         g_free(utf8_filename);
1075 }
1076 #endif
1077
1078 static GtkWidget* smtp_page (WizardWindow * wizard)
1079 {
1080         GtkWidget *table = gtk_table_new(1, 1, FALSE);
1081         GtkWidget *vbox;
1082         GtkWidget *hbox;
1083         GtkWidget *hbox_spc;
1084         GtkWidget *smtp_auth_table;
1085         GtkWidget *label;
1086 #ifdef USE_GNUTLS
1087         GtkWidget *button;
1088         GtkWidget *smtp_cert_table;
1089 #endif
1090         gchar *text;
1091         
1092         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1093         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1094
1095         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1096         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1097
1098         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1099                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1100
1101         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1102         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1103         wizard->smtp_server = gtk_entry_new();
1104         text = get_default_server(wizard, "smtp");
1105         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
1106         g_free(text);
1107
1108         CLAWS_SET_TIP(wizard->smtp_server,
1109                              _("You can specify the port number by appending it at the end: "
1110                                "\"mail.example.com:25\""));
1111
1112         PACK_BOX(hbox, g_strconcat("<span weight=\"bold\">", _("SMTP server address:"),
1113                                    "</span>", NULL), wizard->smtp_server);
1114
1115         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1116         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1117         wizard->smtp_auth = gtk_check_button_new_with_label(
1118                                         _("Use authentication"));
1119         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth),
1120                         tmpl.smtpauth);
1121         g_signal_connect(G_OBJECT(wizard->smtp_auth), "toggled",
1122                          G_CALLBACK(smtp_auth_changed),
1123                          wizard);
1124         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_auth, FALSE, FALSE, 0);
1125
1126         label = gtk_label_new(g_strconcat("<span size=\"small\">",
1127                                           _("(empty to use the same as receive)"), "</span>", NULL));
1128         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1129         SET_TOGGLE_SENSITIVITY (wizard->smtp_auth, label);      
1130         gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1131
1132         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1133         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1134         hbox_spc = gtk_hbox_new (FALSE, 0);
1135         gtk_widget_set_size_request (hbox_spc, 12, -1);
1136         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1137         smtp_auth_table = gtk_table_new(2, 2, FALSE);
1138         SET_TOGGLE_SENSITIVITY (wizard->smtp_auth, smtp_auth_table);
1139         gtk_box_pack_start(GTK_BOX(hbox), smtp_auth_table, TRUE, TRUE, 0);
1140
1141         wizard->smtp_username_label = gtk_label_new(_("SMTP username:"));
1142         gtk_misc_set_alignment(GTK_MISC(wizard->smtp_username_label), 1, 0.5);        
1143         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_username_label, 0,1,0,1, 
1144                          GTK_FILL, 0, VSPACING_NARROW, 0);
1145         text = get_default_smtp_account(wizard);
1146         wizard->smtp_username = gtk_entry_new();
1147         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_username), text);
1148         g_free(text);
1149         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_username, 1,2,0,1, 
1150                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1151
1152         wizard->smtp_password_label = gtk_label_new(_("SMTP password:"));
1153         gtk_misc_set_alignment(GTK_MISC(wizard->smtp_password_label), 1, 0.5);        
1154         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_password_label, 0,1,1,2, 
1155                          GTK_FILL, 0, VSPACING_NARROW, 0);
1156         wizard->smtp_password = gtk_entry_new();
1157         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_password), tmpl.smtppass?tmpl.smtppass:""); 
1158         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_password), FALSE);
1159         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_password, 1,2,1,2, 
1160                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1161 #ifdef USE_GNUTLS
1162         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1163         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1164         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
1165                                         _("Use SSL/TLS to connect to SMTP server"));
1166         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl),
1167                         tmpl.smtpssl != 0);
1168         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_ssl, FALSE, FALSE, 0);
1169
1170         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1171         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1172         hbox_spc = gtk_hbox_new (FALSE, 0);
1173         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1174         gtk_widget_set_size_request (hbox_spc, 12, -1);
1175         wizard->smtp_use_tls = gtk_check_button_new_with_label(
1176                                         _("Use STARTTLS command to start encryption"));
1177         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls),
1178                         tmpl.smtpssl == 2);
1179         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_tls, FALSE, FALSE, 0);
1180         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, wizard->smtp_use_tls);
1181         
1182         smtp_cert_table = gtk_table_new(3,3, FALSE);
1183         gtk_box_pack_start (GTK_BOX(vbox), smtp_cert_table, FALSE, FALSE, 4);
1184         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1185         hbox_spc = gtk_hbox_new (FALSE, 0);
1186         gtk_widget_set_size_request (hbox_spc, 12, -1);
1187         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1188         label = gtk_label_new(_("Client SSL/TLS certificate (optional)"));
1189         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1190         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1191         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
1192         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1193         hbox_spc = gtk_hbox_new (FALSE, 0);
1194         gtk_widget_set_size_request (hbox_spc, 12, -1);
1195         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1196         label = gtk_label_new(_("File"));
1197         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1198         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1199         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 1, 1, 2, 
1200                          GTK_FILL, 0, VSPACING_NARROW, 0);
1201         wizard->smtp_ssl_cert_file = gtk_entry_new();
1202         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_ssl_cert_file), tmpl.smtpssl_cert?tmpl.smtpssl_cert:"");
1203         gtk_table_attach(GTK_TABLE(smtp_cert_table), wizard->smtp_ssl_cert_file, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
1204         button = gtkut_get_browse_file_btn(_("Browse"));
1205         gtk_table_attach(GTK_TABLE(smtp_cert_table), button, 2, 3, 1, 2, 
1206                          GTK_FILL, 0, VSPACING_NARROW, 0);
1207         g_signal_connect(G_OBJECT(button), "clicked",
1208                          G_CALLBACK(cert_browse_cb), wizard->smtp_ssl_cert_file);
1209
1210         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1211         hbox_spc = gtk_hbox_new (FALSE, 0);
1212         gtk_widget_set_size_request (hbox_spc, 12, -1);
1213         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0); 
1214         label = gtk_label_new(_("Password"));
1215         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1216         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1217         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 1, 2, 3, 
1218                          GTK_FILL, 0, VSPACING_NARROW, 0);
1219         wizard->smtp_ssl_cert_pass = gtk_entry_new();
1220         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_ssl_cert_pass), FALSE);
1221         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_ssl_cert_pass), tmpl.smtpssl_cert_pass?tmpl.smtpssl_cert_pass:"");
1222         gtk_table_attach(GTK_TABLE(smtp_cert_table), wizard->smtp_ssl_cert_pass, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
1223         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, smtp_cert_table);
1224         wizard->smtp_cert_table = smtp_cert_table;
1225 #endif
1226         smtp_auth_changed(NULL, wizard);
1227         return table;
1228 }
1229
1230 static void wizard_protocol_change(WizardWindow *wizard, RecvProtocol protocol)
1231 {
1232         gchar *text;
1233         
1234         if (protocol == A_POP3) {
1235                 text = get_default_server(wizard, "pop");
1236                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1237                 gtk_widget_hide(wizard->recv_imap_label);
1238                 gtk_widget_hide(wizard->recv_imap_subdir);
1239                 gtk_widget_hide(wizard->subsonly_checkbtn);
1240                 gtk_widget_show(wizard->recv_username);
1241                 gtk_widget_show(wizard->recv_password);
1242                 gtk_widget_show(wizard->recv_username_label);
1243                 gtk_widget_show(wizard->recv_password_label);
1244                 gtk_widget_hide(wizard->no_imap_warning);
1245 #ifdef USE_GNUTLS
1246                 gtk_widget_show(wizard->recv_use_ssl);
1247                 gtk_widget_show(wizard->recv_use_tls);
1248                 gtk_widget_show(wizard->recv_cert_table);
1249 #endif
1250 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1251                 gtk_widget_show(wizard->auto_configure_btn);
1252                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1253                 gtk_widget_show(wizard->auto_configure_lbl);
1254 #endif
1255                 gtk_label_set_text(GTK_LABEL(wizard->recv_label),
1256                                    g_strconcat("<span weight=\"bold\">", _("Server address:"),
1257                                                 "</span>", NULL));
1258                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1259                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1260                 g_free(text);
1261                 if (wizard->create_mailbox) {
1262                         gtk_widget_show(wizard->mailbox_label);
1263                         gtk_widget_show(wizard->mailbox_name);
1264                 }
1265         } else if (protocol == A_IMAP4) {
1266 #ifdef HAVE_LIBETPAN
1267                 text = get_default_server(wizard, "imap");
1268                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1269                 gtk_widget_show(wizard->recv_imap_label);
1270                 gtk_widget_show(wizard->recv_imap_subdir);
1271                 gtk_widget_show(wizard->subsonly_checkbtn);
1272                 gtk_widget_show(wizard->recv_username);
1273                 gtk_widget_show(wizard->recv_password);
1274                 gtk_widget_show(wizard->recv_username_label);
1275                 gtk_widget_show(wizard->recv_password_label);
1276                 gtk_widget_hide(wizard->no_imap_warning);
1277 #ifdef USE_GNUTLS
1278                 gtk_widget_show(wizard->recv_use_ssl);
1279                 gtk_widget_show(wizard->recv_use_tls);
1280                 gtk_widget_show(wizard->recv_cert_table);
1281 #endif
1282 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1283                 gtk_widget_show(wizard->auto_configure_btn);
1284                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1285                 gtk_widget_show(wizard->auto_configure_lbl);
1286 #endif
1287                 gtk_label_set_text(GTK_LABEL(wizard->recv_label),
1288                                    g_strconcat("<span weight=\"bold\">", _("Server address:"),
1289                                                 "</span>", NULL));
1290                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1291                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1292                 g_free(text);
1293                 if (wizard->create_mailbox) {
1294                         gtk_widget_hide(wizard->mailbox_label);
1295                         gtk_widget_hide(wizard->mailbox_name);
1296                 }
1297 #else
1298                 gtk_widget_hide(wizard->recv_imap_label);
1299                 gtk_widget_hide(wizard->recv_imap_subdir);
1300                 gtk_widget_hide(wizard->subsonly_checkbtn);
1301                 gtk_widget_hide(wizard->recv_username);
1302                 gtk_widget_hide(wizard->recv_password);
1303                 gtk_widget_hide(wizard->recv_username_label);
1304                 gtk_widget_hide(wizard->recv_password_label);
1305                 gtk_widget_show(wizard->no_imap_warning);
1306                 if (wizard->create_mailbox) {
1307                         gtk_widget_hide(wizard->mailbox_label);
1308                         gtk_widget_hide(wizard->mailbox_name);
1309                 }
1310 #ifdef USE_GNUTLS
1311                 gtk_widget_hide(wizard->recv_use_ssl);
1312                 gtk_widget_hide(wizard->recv_use_tls);
1313                 gtk_widget_hide(wizard->recv_cert_table);
1314 #endif
1315                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, FALSE);
1316 #endif
1317         } else if (protocol == A_LOCAL) {
1318                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
1319                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), 
1320                                    g_strconcat("<span weight=\"bold\">", _("Local mailbox:"),
1321                                                "</span>", NULL));
1322                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1323                 gtk_widget_hide(wizard->no_imap_warning);
1324                 gtk_widget_hide(wizard->recv_imap_label);
1325                 gtk_widget_hide(wizard->recv_imap_subdir);
1326                 gtk_widget_hide(wizard->subsonly_checkbtn);
1327                 gtk_widget_hide(wizard->recv_username);
1328                 gtk_widget_hide(wizard->recv_password);
1329                 gtk_widget_hide(wizard->recv_username_label);
1330                 gtk_widget_hide(wizard->recv_password_label);
1331 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1332                 gtk_widget_hide(wizard->auto_configure_btn);
1333                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1334                 gtk_widget_hide(wizard->auto_configure_lbl);
1335 #endif
1336 #ifdef USE_GNUTLS
1337                 gtk_widget_hide(wizard->recv_use_ssl);
1338                 gtk_widget_hide(wizard->recv_use_tls);
1339                 gtk_widget_hide(wizard->recv_cert_table);
1340 #endif
1341                 if (wizard->create_mailbox) {
1342                         gtk_widget_show(wizard->mailbox_label);
1343                         gtk_widget_show(wizard->mailbox_name);
1344                 }
1345                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1346         }
1347 }
1348
1349 static void wizard_protocol_changed(GtkComboBox *combo, gpointer data)
1350 {
1351         WizardWindow *wizard = (WizardWindow *)data;
1352         RecvProtocol protocol = combobox_get_active_data(combo);
1353
1354         wizard_protocol_change(wizard, protocol);       
1355 }
1356
1357 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1358 static void auto_configure_cb (GtkWidget *widget, gpointer data)
1359 {
1360         gchar *address = NULL;
1361         AutoConfigureData *recv_data;
1362         AutoConfigureData *send_data;
1363         static GCancellable *recv_cancel = NULL;
1364         static GCancellable *send_cancel = NULL;
1365         WizardWindow *wizard = (WizardWindow *)data;
1366         RecvProtocol protocol = combobox_get_active_data(GTK_COMBO_BOX(wizard->recv_type));
1367
1368         if (!recv_cancel) {
1369                 recv_cancel = g_cancellable_new();
1370                 send_cancel = g_cancellable_new();
1371         }
1372
1373         if (widget == wizard->auto_configure_cancel_btn) {
1374                 g_cancellable_cancel(recv_cancel);
1375                 g_cancellable_cancel(send_cancel);
1376                 g_object_unref(recv_cancel);
1377                 g_object_unref(send_cancel);
1378                 recv_cancel = NULL;
1379                 send_cancel = NULL;
1380                 return;
1381         }
1382
1383         address = gtk_editable_get_chars(GTK_EDITABLE(wizard->email), 0, -1);
1384
1385         if (strchr(address, '@') == NULL) {
1386                 g_free(address);
1387                 gtk_label_set_text(GTK_LABEL(wizard->auto_configure_lbl),
1388                            _("Failed (wrong address)"));
1389                 return;
1390         }
1391
1392         if (protocol == A_POP3 || protocol == A_IMAP4) {
1393                 recv_data = g_new0(AutoConfigureData, 1);
1394                 recv_data->configure_button = GTK_BUTTON(wizard->auto_configure_btn);
1395                 recv_data->cancel_button = GTK_BUTTON(wizard->auto_configure_cancel_btn);
1396                 recv_data->info_label = GTK_LABEL(wizard->auto_configure_lbl);
1397                 recv_data->uid_entry = GTK_ENTRY(wizard->recv_username);
1398                 recv_data->cancel = recv_cancel;
1399                 switch(protocol) {
1400                 case A_POP3:
1401                         recv_data->ssl_service = "pop3s";
1402                         recv_data->tls_service = "pop3";
1403                         recv_data->address = g_strdup(address);
1404                         recv_data->hostname_entry = GTK_ENTRY(wizard->recv_server);
1405                         recv_data->set_port = NULL;
1406                         recv_data->port = NULL;
1407                         recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_tls);
1408                         recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_ssl);
1409                         recv_data->default_port = 110;
1410                         recv_data->default_ssl_port = 995;
1411                         break;
1412                 case A_IMAP4:
1413                         recv_data->ssl_service = "imaps";
1414                         recv_data->tls_service = "imap";
1415                         recv_data->address = g_strdup(address);
1416                         recv_data->hostname_entry = GTK_ENTRY(wizard->recv_server);
1417                         recv_data->set_port = NULL;
1418                         recv_data->port = NULL;
1419                         recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_tls);
1420                         recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_ssl);
1421                         recv_data->default_port = 143;
1422                         recv_data->default_ssl_port = 993;
1423                         break;
1424                 default:
1425                         cm_return_if_fail(FALSE);
1426                 }
1427                 auto_configure_service(recv_data);
1428         }
1429
1430         send_data = g_new0(AutoConfigureData, 1);
1431         send_data->configure_button = GTK_BUTTON(wizard->auto_configure_btn);
1432         send_data->cancel_button = GTK_BUTTON(wizard->auto_configure_cancel_btn);
1433         send_data->info_label = GTK_LABEL(wizard->auto_configure_lbl);
1434         send_data->cancel = send_cancel;
1435
1436         send_data->ssl_service = NULL;
1437         send_data->tls_service = "submission";
1438         send_data->address = g_strdup(address);
1439         send_data->hostname_entry = GTK_ENTRY(wizard->smtp_server);
1440         send_data->set_port = NULL;
1441         send_data->port = NULL;
1442         send_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_use_tls);
1443         send_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl);
1444         send_data->default_port = 25;
1445         send_data->default_ssl_port = -1;
1446         send_data->auth_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_auth);
1447
1448         auto_configure_service(send_data);
1449
1450         g_free(address);
1451 }
1452 #endif
1453
1454 static GtkWidget* recv_page (WizardWindow * wizard)
1455 {
1456         GtkWidget *table = gtk_table_new(1,1, FALSE);
1457         GtkWidget *vbox;
1458         GtkWidget *hbox;
1459         GtkWidget *hbox_spc;    
1460         GtkWidget *recv_table;
1461         GtkWidget *label;
1462 #ifdef USE_GNUTLS
1463         GtkWidget *button;
1464         GtkWidget *recv_cert_table;
1465 #endif
1466 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1467         GtkWidget *auto_configure_btn;
1468         GtkWidget *auto_configure_cancel_btn;
1469         GtkWidget *auto_configure_lbl;
1470 #endif
1471         GtkListStore *store;
1472         GtkTreeIter iter;
1473         gchar *text;
1474         gint index = 0;
1475
1476         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1477         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1478
1479         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1480         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1481
1482         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1483                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1484
1485         recv_table = gtk_table_new(4, 2, FALSE); 
1486
1487         gtk_box_pack_start(GTK_BOX(vbox), recv_table, FALSE, FALSE, 0);
1488
1489         label = gtk_label_new(g_strconcat("<span weight=\"bold\">", _("Server type:"), "</span>", NULL));
1490         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1491         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1492         gtk_table_attach(GTK_TABLE(recv_table), label, 0,1,0,1, 
1493                          GTK_FILL, 0, VSPACING_NARROW, 0);
1494         wizard->recv_type = gtkut_sc_combobox_create(NULL, FALSE);
1495         store = GTK_LIST_STORE(gtk_combo_box_get_model(
1496                         GTK_COMBO_BOX(wizard->recv_type)));
1497
1498         COMBOBOX_ADD(store, _("POP3"), A_POP3);
1499         COMBOBOX_ADD(store, _("IMAP"), A_IMAP4);
1500         COMBOBOX_ADD(store, _("Local mbox file"), A_LOCAL);
1501
1502         switch(tmpl.recvtype) {
1503         case A_POP3: 
1504                 index = 0;
1505                 break;
1506         case A_IMAP4:
1507                 index = 1;
1508                 break;
1509         case A_LOCAL:
1510                 index = 2;
1511                 break;
1512         default:
1513                 index = 0;
1514         }
1515         gtk_combo_box_set_active(GTK_COMBO_BOX (wizard->recv_type), index);
1516         g_signal_connect(G_OBJECT(wizard->recv_type), "changed",
1517                          G_CALLBACK(wizard_protocol_changed),
1518                          wizard);
1519         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_type, 1,2,0,1, 
1520                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1521
1522 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1523         auto_configure_btn = gtk_button_new_with_label(_("Auto-configure"));
1524         auto_configure_cancel_btn = gtk_button_new_with_label(_("Cancel"));
1525         gtk_table_attach(GTK_TABLE(recv_table), auto_configure_btn, 0,1,1,2,
1526                         GTK_FILL, 0, VSPACING_NARROW, 0);
1527         auto_configure_lbl = gtk_label_new("");
1528         gtk_misc_set_alignment(GTK_MISC(auto_configure_lbl), 0, 0.5);
1529         gtk_table_attach(GTK_TABLE(recv_table), auto_configure_lbl, 1,2,1,2,
1530                         GTK_FILL, 0, VSPACING_NARROW, 0);
1531         gtk_widget_show(auto_configure_btn);
1532         gtk_widget_show(auto_configure_lbl);
1533         wizard->auto_configure_lbl = auto_configure_lbl;
1534         wizard->auto_configure_btn = auto_configure_btn;
1535         wizard->auto_configure_cancel_btn = auto_configure_cancel_btn;
1536         g_signal_connect (G_OBJECT (auto_configure_btn), "clicked",
1537                           G_CALLBACK (auto_configure_cb), wizard);
1538         g_signal_connect (G_OBJECT (auto_configure_cancel_btn), "clicked",
1539                           G_CALLBACK (auto_configure_cb), wizard);
1540 #endif
1541
1542         wizard->recv_label = gtk_label_new(g_strconcat("<span weight=\"bold\">",
1543                                                 _("Server address:"), "</span>", NULL));
1544         gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);
1545         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1546         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_label, 0,1,2,3,
1547                          GTK_FILL, 0, VSPACING_NARROW, 0);
1548         wizard->recv_server = gtk_entry_new();
1549         text = get_default_server(wizard, "pop");
1550         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1551         g_free(text);
1552         
1553         CLAWS_SET_TIP(wizard->recv_server,
1554                              _("You can specify the port number by appending it at the end: "
1555                                "\"mail.example.com:110\""));
1556         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_server, 1,2,2,3,
1557                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1558         
1559         wizard->recv_username_label = gtk_label_new(g_strconcat("<span weight=\"bold\">",
1560                                                                 _("Username:"),"</span>", NULL));
1561         gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);
1562         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_username_label), TRUE);
1563         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_username_label, 0,1,3,4,
1564                          GTK_FILL, 0, VSPACING_NARROW, 0);
1565         wizard->recv_username = gtk_entry_new();
1566         text = get_default_account(wizard);
1567         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
1568         g_free(text);
1569         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_username, 1,2,3,4,
1570                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1571                          
1572         wizard->recv_password_label = gtk_label_new(_("Password:"));
1573         gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);
1574         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_password_label, 0,1,4,5,
1575                          GTK_FILL, 0, VSPACING_NARROW, 0);
1576         wizard->recv_password = gtk_entry_new();
1577         gtk_entry_set_text(GTK_ENTRY(wizard->recv_password), tmpl.recvpass?tmpl.recvpass:"");
1578         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
1579         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_password, 1,2,4,5,
1580                          GTK_EXPAND|GTK_FILL, 0, 0, 0); 
1581 #ifdef USE_GNUTLS
1582         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1583         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1584         wizard->recv_use_ssl = gtk_check_button_new_with_label(
1585                                         _("Use SSL/TLS to connect to receiving server"));
1586         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl),
1587                         tmpl.recvssl != 0);
1588         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_ssl, FALSE, FALSE, 0);
1589
1590         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1591         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1592         hbox_spc = gtk_hbox_new (FALSE, 0);
1593         gtk_widget_set_size_request (hbox_spc, 12, -1);
1594         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0); 
1595         wizard->recv_use_tls = gtk_check_button_new_with_label(
1596                                         _("Use STARTTLS command to start encryption"));
1597         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls),
1598                         tmpl.recvssl == 2);
1599         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_tls, FALSE, FALSE, 0);
1600         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, wizard->recv_use_tls);
1601
1602         recv_cert_table = gtk_table_new(3,3, FALSE);
1603         gtk_box_pack_start (GTK_BOX(vbox), recv_cert_table, FALSE, FALSE, 4);
1604         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1605         hbox_spc = gtk_hbox_new (FALSE, 0);
1606         gtk_widget_set_size_request (hbox_spc, 12, -1);
1607         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1608         label = gtk_label_new(_("Client SSL/TLS certificate (optional)"));
1609         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1610         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);    
1611         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
1612         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1613         hbox_spc = gtk_hbox_new (FALSE, 0);
1614         gtk_widget_set_size_request (hbox_spc, 12, -1);
1615         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1616         label = gtk_label_new(_("File"));
1617         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1618         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);      
1619         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 1, 1, 2, 
1620                          GTK_FILL, 0, VSPACING_NARROW, 0);
1621         wizard->recv_ssl_cert_file = gtk_entry_new();
1622         gtk_entry_set_text(GTK_ENTRY(wizard->recv_ssl_cert_file), tmpl.recvssl_cert?tmpl.recvssl_cert:"");
1623         gtk_table_attach(GTK_TABLE(recv_cert_table), wizard->recv_ssl_cert_file, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
1624         button = gtkut_get_browse_file_btn(_("Browse"));
1625         gtk_table_attach(GTK_TABLE(recv_cert_table), button, 2, 3, 1, 2, 
1626                          GTK_FILL, 0, VSPACING_NARROW, 0);
1627         g_signal_connect(G_OBJECT(button), "clicked",
1628                          G_CALLBACK(cert_browse_cb), wizard->recv_ssl_cert_file);
1629
1630         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1631         hbox_spc = gtk_hbox_new (FALSE, 0);
1632         gtk_widget_set_size_request (hbox_spc, 12, -1);
1633         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1634         label = gtk_label_new(_("Password"));
1635         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1636         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1637         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 1, 2, 3, 
1638                          GTK_FILL, 0, VSPACING_NARROW, 0);
1639         wizard->recv_ssl_cert_pass = gtk_entry_new();
1640         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_ssl_cert_pass), FALSE);
1641         gtk_entry_set_text(GTK_ENTRY(wizard->recv_ssl_cert_pass), tmpl.recvssl_cert_pass?tmpl.recvssl_cert_pass:"");
1642         gtk_table_attach(GTK_TABLE(recv_cert_table), wizard->recv_ssl_cert_pass, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
1643         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, recv_cert_table); 
1644         wizard->recv_cert_table = recv_cert_table;
1645 #endif  
1646         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1647         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1648         wizard->recv_imap_subdir = gtk_entry_new();
1649         gtk_entry_set_text(GTK_ENTRY(wizard->recv_imap_subdir), tmpl.imapdir?tmpl.imapdir:"");
1650         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
1651         gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
1652         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_label, FALSE, FALSE, 0);
1653         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_subdir, TRUE, TRUE, 0);
1654         
1655         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1656         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1657         hbox_spc = gtk_hbox_new (FALSE, 0);
1658         gtk_widget_set_size_request (hbox_spc, 12, -1);
1659         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1660         wizard->subsonly_checkbtn = gtk_check_button_new_with_label(
1661                         _("Show only subscribed folders"));
1662         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn),
1663                         tmpl.subsonly);
1664         gtk_box_pack_start(GTK_BOX(hbox), wizard->subsonly_checkbtn, FALSE, FALSE, 0);
1665         
1666         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1667         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1668         wizard->no_imap_warning = gtk_label_new(g_strconcat("<span weight=\"bold\">",
1669                         _("Warning: this version of Claws Mail\n"
1670                           "has been built without IMAP support."), "</span>", NULL));
1671         gtk_label_set_use_markup(GTK_LABEL(wizard->no_imap_warning), TRUE);
1672         gtk_box_pack_start(GTK_BOX(hbox), wizard->no_imap_warning, FALSE, FALSE, 0);
1673
1674         return table;
1675 }
1676
1677 static void
1678 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
1679 {
1680         WizardWindow * wizard = (WizardWindow *)data;
1681         int current_page, num_pages;
1682         gboolean skip_mailbox_page = FALSE;
1683         gint protocol = combobox_get_active_data(GTK_COMBO_BOX(wizard->recv_type));
1684
1685         if (protocol == A_IMAP4) {
1686                 skip_mailbox_page = TRUE;
1687         }
1688
1689         num_pages = g_slist_length(wizard->pages);
1690
1691         current_page = gtk_notebook_get_current_page (
1692                                 GTK_NOTEBOOK(wizard->notebook));
1693         if (response == CANCEL)
1694         {
1695                 wizard->result = FALSE;
1696                 wizard->finished = TRUE;
1697                 gtk_widget_destroy (GTK_WIDGET(dialog));
1698         }
1699         else if (response == FINISHED)
1700         {
1701                 if (!wizard_write_config(wizard)) {
1702                         current_page = gtk_notebook_get_current_page (
1703                                         GTK_NOTEBOOK(wizard->notebook));
1704                         goto set_sens;
1705                 }
1706                 wizard->result = TRUE;
1707                 wizard->finished = TRUE;
1708                 gtk_widget_destroy (GTK_WIDGET(dialog));
1709         }
1710         else
1711         {
1712                 if (response == GO_BACK)
1713                 {
1714                         if (current_page > 0) {
1715                                 current_page--;
1716                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1717                                         /* mailbox */
1718                                         current_page--;
1719                                 }
1720                                 gtk_notebook_set_current_page (
1721                                         GTK_NOTEBOOK(wizard->notebook), 
1722                                         current_page);
1723                         }
1724                 }
1725                 else if (response == GO_FORWARD)
1726                 {
1727                         if (current_page < (num_pages-1)) {
1728                                 current_page++;
1729                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1730                                         /* mailbox */
1731                                         current_page++;
1732                                 }
1733                                 gtk_notebook_set_current_page (
1734                                         GTK_NOTEBOOK(wizard->notebook), 
1735                                         current_page);
1736                         }
1737                 }
1738 set_sens:
1739                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
1740                                 current_page > 0);
1741                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
1742                                 current_page < (num_pages - 1));
1743                 if (current_page == (num_pages -1)) {
1744                         gtk_dialog_set_response_sensitive (dialog, FINISHED, TRUE);
1745                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), FINISHED);
1746                 } else {
1747                         gtk_dialog_set_response_sensitive (dialog, FINISHED, FALSE);
1748                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), GO_FORWARD);
1749                 }
1750
1751         }
1752 }
1753
1754 static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
1755                                  gpointer data)
1756 {
1757         WizardWindow *wizard = (WizardWindow *)data;
1758         wizard->result = FALSE;
1759         wizard->finished = TRUE;
1760         
1761         return FALSE;
1762 }
1763
1764 #define PACK_WARNING(text) {                                            \
1765         label = gtk_label_new(text);                                    \
1766         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);                  \
1767         gtk_box_pack_end(GTK_BOX(widget), label, FALSE, FALSE, 0);      \
1768 }
1769
1770 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
1771         WizardWindow *wizard = g_new0(WizardWindow, 1);
1772         GtkWidget *page;
1773         GtkWidget *widget;
1774         GtkWidget *label;
1775         GtkWidget *scrolled_window;
1776         gchar     *text;
1777         GSList    *cur;
1778         gboolean   result;
1779         gint i = 0;
1780         wizard->mainwin = mainwin;
1781         wizard->create_mailbox = create_mailbox;
1782         
1783         gtk_widget_hide(mainwin->window);
1784         
1785         wizard_read_defaults();
1786         
1787         wizard->window = gtk_dialog_new_with_buttons (_("Claws Mail Setup Wizard"),
1788                         NULL, 0, 
1789                         GTK_STOCK_GO_BACK, GO_BACK,
1790                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
1791                         GTK_STOCK_SAVE, FINISHED,
1792                         GTK_STOCK_CANCEL, CANCEL,
1793                         NULL);
1794         gtk_widget_set_size_request(wizard->window, -1, 480);
1795         gtk_window_set_position(GTK_WINDOW(wizard->window), GTK_WIN_POS_CENTER);
1796
1797         g_signal_connect(wizard->window, "response", 
1798                           G_CALLBACK(wizard_response_cb), wizard);
1799         gtk_widget_realize(wizard->window);
1800         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
1801                         GO_FORWARD);
1802         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1803                         GO_BACK, FALSE);
1804         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1805                         GO_FORWARD, TRUE);
1806         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1807                         FINISHED, FALSE);
1808         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1809                         CANCEL, TRUE);
1810         
1811         wizard->notebook = gtk_notebook_new();
1812         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
1813         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
1814         gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(wizard->window))), 
1815                             wizard->notebook, TRUE, TRUE, 0);
1816         
1817         wizard->pages = NULL;
1818         
1819 /*welcome page: 0 */
1820         WELCOME_PAGE = i;
1821         page = create_page(wizard, _("Welcome to Claws Mail"));
1822         
1823         wizard->pages = g_slist_append(wizard->pages, page);
1824         widget = stock_pixmap_widget(STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1825
1826         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1827         
1828         text = g_strdup(_("Welcome to the Claws Mail setup wizard.\n\n"
1829                           "We will begin by defining some basic "
1830                           "information about you and your most common "
1831                           "mail options so that you can start to use "
1832                           "Claws Mail in less than five minutes."));
1833         widget = gtk_label_new(text);
1834         gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
1835         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1836         g_free(text);
1837
1838 /* user page: 1 */
1839         i++;
1840         USER_PAGE = i;
1841         widget = create_page (wizard, _("About You"));
1842         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1843         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1844                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1845         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1846
1847         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1848                                               user_page(wizard));
1849         PACK_WARNING(_("Bold fields must be completed"));
1850         
1851         wizard->pages = g_slist_append(wizard->pages, widget);
1852
1853 /* recv+auth page: 2 */
1854         i++;
1855         RECV_PAGE = i;
1856         widget = create_page (wizard, _("Receiving mail"));
1857         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1858         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1859                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1860         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1861
1862         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1863                                               recv_page(wizard));
1864         PACK_WARNING(_("Bold fields must be completed"));
1865         
1866         wizard->pages = g_slist_append(wizard->pages, widget);
1867
1868 /*smtp page: 3 */
1869         i++;
1870         SMTP_PAGE = i;
1871         widget = create_page (wizard, _("Sending mail"));
1872         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1873         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1874                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1875         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1876
1877         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1878                                               smtp_page(wizard));
1879         PACK_WARNING(_("Bold fields must be completed"));
1880         
1881         wizard->pages = g_slist_append(wizard->pages, widget);
1882
1883 /* mailbox page: 4 */
1884         if (create_mailbox) {
1885                 i++;
1886                 MAILBOX_PAGE = i;
1887                 widget = create_page (wizard, _("Saving mail on disk"));
1888                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1889                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1890                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1891                 gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1892
1893                 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1894                                               mailbox_page(wizard));
1895                 PACK_WARNING(_("Bold fields must be completed"));
1896         
1897                 wizard->pages = g_slist_append(wizard->pages, widget);
1898         }
1899
1900 /* done page: 6 */
1901         i++;
1902         DONE_PAGE = i;
1903         page = create_page(wizard, _("Configuration finished"));
1904         
1905         wizard->pages = g_slist_append(wizard->pages, page);
1906         widget = stock_pixmap_widget(STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1907
1908         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1909         
1910         text = g_strdup(_("Claws Mail is now ready.\n"
1911                           "Click Save to start."));
1912         widget = gtk_label_new(text);
1913         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1914         g_free(text);
1915
1916
1917         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
1918                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
1919                                           GTK_WIDGET(cur->data), NULL);
1920         }
1921         
1922         g_signal_connect(G_OBJECT(wizard->window), "delete_event",
1923                          G_CALLBACK(wizard_close_cb), wizard);
1924         gtk_widget_show_all (wizard->window);
1925
1926         gtk_widget_hide(wizard->recv_imap_label);
1927         gtk_widget_hide(wizard->recv_imap_subdir);
1928         gtk_widget_hide(wizard->subsonly_checkbtn);
1929 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1930         gtk_widget_hide(wizard->auto_configure_cancel_btn);
1931 #endif
1932         wizard_protocol_change(wizard, tmpl.recvtype);
1933
1934         while (!wizard->finished)
1935                 gtk_main_iteration();
1936
1937         result = wizard->result;
1938         
1939         GTK_EVENTS_FLUSH();
1940
1941         gtk_widget_show(mainwin->window);
1942         g_free(wizard);
1943
1944         return result;
1945 }