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