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