Moved struct and enum declarations from prefswindow.c to .h.
[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(_("<span weight=\"bold\">Your name:</span>"));
969         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
970         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
971         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,0,1, 
972                          GTK_FILL, 0, VSPACING_NARROW, 0);
973         wizard->full_name = gtk_entry_new();
974         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), tmpl.name?tmpl.name:"");
975         gtk_table_attach(GTK_TABLE(user_table), wizard->full_name, 1,2,0,1, 
976                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
977
978         label = gtk_label_new(_("<span weight=\"bold\">Your email address:</span>"));
979         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
980         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
981         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,1,2, 
982                          GTK_FILL, 0, VSPACING_NARROW, 0);
983         wizard->email = gtk_entry_new();
984         gtk_entry_set_text(GTK_ENTRY(wizard->email), tmpl.email?tmpl.email:"");
985         gtk_table_attach(GTK_TABLE(user_table), wizard->email, 1,2,1,2, 
986                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
987
988         label = gtk_label_new(_("Your organization:"));
989         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
990         gtk_table_attach(GTK_TABLE(user_table), label, 0,1,2,3, 
991                          GTK_FILL, 0, VSPACING_NARROW, 0);
992         wizard->organization = gtk_entry_new();
993         gtk_entry_set_text(GTK_ENTRY(wizard->organization), tmpl.organization?tmpl.organization:"");
994         gtk_table_attach(GTK_TABLE(user_table), wizard->organization, 1,2,2,3, 
995                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
996         
997         g_signal_connect(G_OBJECT(wizard->email), "changed",
998                          G_CALLBACK(wizard_email_changed),
999                          wizard);
1000         return table;
1001 }
1002
1003 static GtkWidget* mailbox_page (WizardWindow * wizard)
1004 {
1005         GtkWidget *table = gtk_table_new(1,1, FALSE);
1006         GtkWidget *vbox;
1007         GtkWidget *hbox;
1008
1009         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1010         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1011
1012         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1013         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1014
1015         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1016                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1017
1018         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1019         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1020
1021         wizard->mailbox_label = gtk_label_new(_("<span weight=\"bold\">Mailbox name:</span>"));
1022         gtk_label_set_use_markup(GTK_LABEL(wizard->mailbox_label), TRUE);
1023         if (GTK_IS_MISC(wizard->mailbox_label))                                               
1024                 gtk_misc_set_alignment(GTK_MISC(wizard->mailbox_label), 1, 0.5);              
1025         wizard->mailbox_name = gtk_entry_new();
1026
1027         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), tmpl.mailbox?tmpl.mailbox:"");
1028
1029         CLAWS_SET_TIP(wizard->mailbox_name, _("You can also specify an absolute path, for example: "
1030                                "\"/home/john/Documents/Mail\""));
1031
1032         gtk_box_pack_start(GTK_BOX(hbox), wizard->mailbox_label, FALSE, FALSE, 0);
1033         gtk_box_pack_start(GTK_BOX(hbox), wizard->mailbox_name, TRUE, TRUE, 0);
1034
1035         return table;
1036 }
1037
1038 static void smtp_auth_changed (GtkWidget *btn, gpointer data)
1039 {
1040         WizardWindow *wizard = (WizardWindow *)data;
1041         gboolean do_auth = gtk_toggle_button_get_active(
1042                 GTK_TOGGLE_BUTTON(wizard->smtp_auth));
1043         gtk_widget_set_sensitive(wizard->smtp_username, do_auth);
1044         gtk_widget_set_sensitive(wizard->smtp_username_label, do_auth);
1045         gtk_widget_set_sensitive(wizard->smtp_password, do_auth);
1046         gtk_widget_set_sensitive(wizard->smtp_password_label, do_auth);
1047 }
1048
1049 #ifdef USE_GNUTLS
1050 static void cert_browse_cb(GtkWidget *widget, gpointer data)
1051 {
1052         GtkEntry *dest = GTK_ENTRY(data);
1053         gchar *filename;
1054         gchar *utf8_filename;
1055
1056         filename = filesel_select_file_open(_("Select certificate file"), NULL);
1057         if (!filename) return;
1058
1059         utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
1060         if (!utf8_filename) {
1061                 g_warning("cert_browse_cb(): failed to convert character set.");
1062                 utf8_filename = g_strdup(filename);
1063         }
1064         gtk_entry_set_text(dest, utf8_filename);
1065         g_free(utf8_filename);
1066 }
1067 #endif
1068
1069 static GtkWidget* smtp_page (WizardWindow * wizard)
1070 {
1071         GtkWidget *table = gtk_table_new(1, 1, FALSE);
1072         GtkWidget *vbox;
1073         GtkWidget *hbox;
1074         GtkWidget *hbox_spc;
1075         GtkWidget *smtp_auth_table;
1076         GtkWidget *label;
1077 #ifdef USE_GNUTLS
1078         GtkWidget *button;
1079         GtkWidget *smtp_cert_table;
1080 #endif
1081         gchar *text;
1082         
1083         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1084         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1085
1086         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1087         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1088
1089         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1090                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1091
1092         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1093         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1094         wizard->smtp_server = gtk_entry_new();
1095         text = get_default_server(wizard, "smtp");
1096         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
1097         g_free(text);
1098
1099         CLAWS_SET_TIP(wizard->smtp_server,
1100                              _("You can specify the port number by appending it at the end: "
1101                                "\"mail.example.com:25\""));
1102
1103         PACK_BOX(hbox, _("<span weight=\"bold\">SMTP server address:</span>"),
1104                  wizard->smtp_server);
1105
1106         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1107         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1108         wizard->smtp_auth = gtk_check_button_new_with_label(
1109                                         _("Use authentication"));
1110         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth),
1111                         tmpl.smtpauth);
1112         g_signal_connect(G_OBJECT(wizard->smtp_auth), "toggled",
1113                          G_CALLBACK(smtp_auth_changed),
1114                          wizard);
1115         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_auth, FALSE, FALSE, 0);
1116
1117         label = gtk_label_new(_("<span size=\"small\">(empty to use the same as receive)</span>"));
1118         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1119         SET_TOGGLE_SENSITIVITY (wizard->smtp_auth, label);      
1120         gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1121
1122         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1123         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1124         hbox_spc = gtk_hbox_new (FALSE, 0);
1125         gtk_widget_set_size_request (hbox_spc, 12, -1);
1126         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1127         smtp_auth_table = gtk_table_new(2, 2, FALSE);
1128         SET_TOGGLE_SENSITIVITY (wizard->smtp_auth, smtp_auth_table);
1129         gtk_box_pack_start(GTK_BOX(hbox), smtp_auth_table, TRUE, TRUE, 0);
1130
1131         wizard->smtp_username_label = gtk_label_new(_("SMTP username:"));
1132         gtk_misc_set_alignment(GTK_MISC(wizard->smtp_username_label), 1, 0.5);        
1133         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_username_label, 0,1,0,1, 
1134                          GTK_FILL, 0, VSPACING_NARROW, 0);
1135         text = get_default_smtp_account(wizard);
1136         wizard->smtp_username = gtk_entry_new();
1137         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_username), text);
1138         g_free(text);
1139         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_username, 1,2,0,1, 
1140                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1141
1142         wizard->smtp_password_label = gtk_label_new(_("SMTP password:"));
1143         gtk_misc_set_alignment(GTK_MISC(wizard->smtp_password_label), 1, 0.5);        
1144         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_password_label, 0,1,1,2, 
1145                          GTK_FILL, 0, VSPACING_NARROW, 0);
1146         wizard->smtp_password = gtk_entry_new();
1147         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_password), tmpl.smtppass?tmpl.smtppass:""); 
1148         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_password), FALSE);
1149         gtk_table_attach(GTK_TABLE(smtp_auth_table), wizard->smtp_password, 1,2,1,2, 
1150                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1151 #ifdef USE_GNUTLS
1152         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1153         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1154         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
1155                                         _("Use SSL to connect to SMTP server"));
1156         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl),
1157                         tmpl.smtpssl != 0);
1158         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_ssl, FALSE, FALSE, 0);
1159
1160         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1161         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1162         hbox_spc = gtk_hbox_new (FALSE, 0);
1163         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1164         gtk_widget_set_size_request (hbox_spc, 12, -1);
1165         wizard->smtp_use_tls = gtk_check_button_new_with_label(
1166                                         _("Use SSL via STARTTLS"));
1167         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls),
1168                         tmpl.smtpssl == 2);
1169         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_tls, FALSE, FALSE, 0);
1170         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, wizard->smtp_use_tls);
1171         
1172         smtp_cert_table = gtk_table_new(3,3, FALSE);
1173         gtk_box_pack_start (GTK_BOX(vbox), smtp_cert_table, FALSE, FALSE, 4);
1174         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1175         hbox_spc = gtk_hbox_new (FALSE, 0);
1176         gtk_widget_set_size_request (hbox_spc, 12, -1);
1177         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1178         label = gtk_label_new(_("Client SSL certificate (optional)"));
1179         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1180         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1181         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
1182         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1183         hbox_spc = gtk_hbox_new (FALSE, 0);
1184         gtk_widget_set_size_request (hbox_spc, 12, -1);
1185         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1186         label = gtk_label_new(_("File"));
1187         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1188         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1189         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 1, 1, 2, 
1190                          GTK_FILL, 0, VSPACING_NARROW, 0);
1191         wizard->smtp_ssl_cert_file = gtk_entry_new();
1192         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_ssl_cert_file), tmpl.smtpssl_cert?tmpl.smtpssl_cert:"");
1193         gtk_table_attach(GTK_TABLE(smtp_cert_table), wizard->smtp_ssl_cert_file, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
1194         button = gtkut_get_browse_file_btn(_("Browse"));
1195         gtk_table_attach(GTK_TABLE(smtp_cert_table), button, 2, 3, 1, 2, 
1196                          GTK_FILL, 0, VSPACING_NARROW, 0);
1197         g_signal_connect(G_OBJECT(button), "clicked",
1198                          G_CALLBACK(cert_browse_cb), wizard->smtp_ssl_cert_file);
1199
1200         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1201         hbox_spc = gtk_hbox_new (FALSE, 0);
1202         gtk_widget_set_size_request (hbox_spc, 12, -1);
1203         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0); 
1204         label = gtk_label_new(_("Password"));
1205         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1206         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1207         gtk_table_attach(GTK_TABLE(smtp_cert_table), hbox, 0, 1, 2, 3, 
1208                          GTK_FILL, 0, VSPACING_NARROW, 0);
1209         wizard->smtp_ssl_cert_pass = gtk_entry_new();
1210         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_ssl_cert_pass), FALSE);
1211         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_ssl_cert_pass), tmpl.smtpssl_cert_pass?tmpl.smtpssl_cert_pass:"");
1212         gtk_table_attach(GTK_TABLE(smtp_cert_table), wizard->smtp_ssl_cert_pass, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
1213         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, smtp_cert_table);
1214         wizard->smtp_cert_table = smtp_cert_table;
1215 #endif
1216         smtp_auth_changed(NULL, wizard);
1217         return table;
1218 }
1219
1220 static void wizard_protocol_change(WizardWindow *wizard, RecvProtocol protocol)
1221 {
1222         gchar *text;
1223         
1224         if (protocol == A_POP3) {
1225                 text = get_default_server(wizard, "pop");
1226                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1227                 gtk_widget_hide(wizard->recv_imap_label);
1228                 gtk_widget_hide(wizard->recv_imap_subdir);
1229                 gtk_widget_hide(wizard->subsonly_checkbtn);
1230                 gtk_widget_show(wizard->recv_username);
1231                 gtk_widget_show(wizard->recv_password);
1232                 gtk_widget_show(wizard->recv_username_label);
1233                 gtk_widget_show(wizard->recv_password_label);
1234                 gtk_widget_hide(wizard->no_imap_warning);
1235 #ifdef USE_GNUTLS
1236                 gtk_widget_show(wizard->recv_use_ssl);
1237                 gtk_widget_show(wizard->recv_use_tls);
1238                 gtk_widget_show(wizard->recv_cert_table);
1239 #endif
1240 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1241                 gtk_widget_show(wizard->auto_configure_btn);
1242                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1243                 gtk_widget_show(wizard->auto_configure_lbl);
1244 #endif
1245                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1246                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1247                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1248                 g_free(text);
1249                 if (wizard->create_mailbox) {
1250                         gtk_widget_show(wizard->mailbox_label);
1251                         gtk_widget_show(wizard->mailbox_name);
1252                 }
1253         } else if (protocol == A_IMAP4) {
1254 #ifdef HAVE_LIBETPAN
1255                 text = get_default_server(wizard, "imap");
1256                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1257                 gtk_widget_show(wizard->recv_imap_label);
1258                 gtk_widget_show(wizard->recv_imap_subdir);
1259                 gtk_widget_show(wizard->subsonly_checkbtn);
1260                 gtk_widget_show(wizard->recv_username);
1261                 gtk_widget_show(wizard->recv_password);
1262                 gtk_widget_show(wizard->recv_username_label);
1263                 gtk_widget_show(wizard->recv_password_label);
1264                 gtk_widget_hide(wizard->no_imap_warning);
1265 #ifdef USE_GNUTLS
1266                 gtk_widget_show(wizard->recv_use_ssl);
1267                 gtk_widget_show(wizard->recv_use_tls);
1268                 gtk_widget_show(wizard->recv_cert_table);
1269 #endif
1270 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1271                 gtk_widget_show(wizard->auto_configure_btn);
1272                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1273                 gtk_widget_show(wizard->auto_configure_lbl);
1274 #endif
1275                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1276                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1277                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1278                 g_free(text);
1279                 if (wizard->create_mailbox) {
1280                         gtk_widget_hide(wizard->mailbox_label);
1281                         gtk_widget_hide(wizard->mailbox_name);
1282                 }
1283 #else
1284                 gtk_widget_hide(wizard->recv_imap_label);
1285                 gtk_widget_hide(wizard->recv_imap_subdir);
1286                 gtk_widget_hide(wizard->subsonly_checkbtn);
1287                 gtk_widget_hide(wizard->recv_username);
1288                 gtk_widget_hide(wizard->recv_password);
1289                 gtk_widget_hide(wizard->recv_username_label);
1290                 gtk_widget_hide(wizard->recv_password_label);
1291                 gtk_widget_show(wizard->no_imap_warning);
1292                 if (wizard->create_mailbox) {
1293                         gtk_widget_hide(wizard->mailbox_label);
1294                         gtk_widget_hide(wizard->mailbox_name);
1295                 }
1296 #ifdef USE_GNUTLS
1297                 gtk_widget_hide(wizard->recv_use_ssl);
1298                 gtk_widget_hide(wizard->recv_use_tls);
1299                 gtk_widget_hide(wizard->recv_cert_table);
1300 #endif
1301                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, FALSE);
1302 #endif
1303         } else if (protocol == A_LOCAL) {
1304                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
1305                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Local mailbox:</span>"));
1306                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1307                 gtk_widget_hide(wizard->no_imap_warning);
1308                 gtk_widget_hide(wizard->recv_imap_label);
1309                 gtk_widget_hide(wizard->recv_imap_subdir);
1310                 gtk_widget_hide(wizard->subsonly_checkbtn);
1311                 gtk_widget_hide(wizard->recv_username);
1312                 gtk_widget_hide(wizard->recv_password);
1313                 gtk_widget_hide(wizard->recv_username_label);
1314                 gtk_widget_hide(wizard->recv_password_label);
1315 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1316                 gtk_widget_hide(wizard->auto_configure_btn);
1317                 gtk_widget_hide(wizard->auto_configure_cancel_btn);
1318                 gtk_widget_hide(wizard->auto_configure_lbl);
1319 #endif
1320 #ifdef USE_GNUTLS
1321                 gtk_widget_hide(wizard->recv_use_ssl);
1322                 gtk_widget_hide(wizard->recv_use_tls);
1323                 gtk_widget_hide(wizard->recv_cert_table);
1324 #endif
1325                 if (wizard->create_mailbox) {
1326                         gtk_widget_show(wizard->mailbox_label);
1327                         gtk_widget_show(wizard->mailbox_name);
1328                 }
1329                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1330         }
1331 }
1332
1333 static void wizard_protocol_changed(GtkComboBox *combo, gpointer data)
1334 {
1335         WizardWindow *wizard = (WizardWindow *)data;
1336         RecvProtocol protocol = combobox_get_active_data(combo);
1337
1338         wizard_protocol_change(wizard, protocol);       
1339 }
1340
1341 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1342 static void auto_configure_cb (GtkWidget *widget, gpointer data)
1343 {
1344         gchar *address = NULL;
1345         AutoConfigureData *recv_data;
1346         AutoConfigureData *send_data;
1347         static GCancellable *recv_cancel = NULL;
1348         static GCancellable *send_cancel = NULL;
1349         WizardWindow *wizard = (WizardWindow *)data;
1350         RecvProtocol protocol = combobox_get_active_data(GTK_COMBO_BOX(wizard->recv_type));
1351
1352         if (!recv_cancel) {
1353                 recv_cancel = g_cancellable_new();
1354                 send_cancel = g_cancellable_new();
1355         }
1356
1357         if (widget == wizard->auto_configure_cancel_btn) {
1358                 g_cancellable_cancel(recv_cancel);
1359                 g_cancellable_cancel(send_cancel);
1360                 g_object_unref(recv_cancel);
1361                 g_object_unref(send_cancel);
1362                 recv_cancel = NULL;
1363                 send_cancel = NULL;
1364                 return;
1365         }
1366
1367         address = gtk_editable_get_chars(GTK_EDITABLE(wizard->email), 0, -1);
1368
1369         if (strchr(address, '@') == NULL) {
1370                 g_free(address);
1371                 gtk_label_set_text(GTK_LABEL(wizard->auto_configure_lbl),
1372                            _("Failed (wrong address)"));
1373                 return;
1374         }
1375
1376         if (protocol == A_POP3 || protocol == A_IMAP4) {
1377                 recv_data = g_new0(AutoConfigureData, 1);
1378                 recv_data->configure_button = GTK_BUTTON(wizard->auto_configure_btn);
1379                 recv_data->cancel_button = GTK_BUTTON(wizard->auto_configure_cancel_btn);
1380                 recv_data->info_label = GTK_LABEL(wizard->auto_configure_lbl);
1381                 recv_data->uid_entry = GTK_ENTRY(wizard->recv_username);
1382                 recv_data->cancel = recv_cancel;
1383                 switch(protocol) {
1384                 case A_POP3:
1385                         recv_data->ssl_service = "pop3s";
1386                         recv_data->tls_service = "pop3";
1387                         recv_data->address = g_strdup(address);
1388                         recv_data->hostname_entry = GTK_ENTRY(wizard->recv_server);
1389                         recv_data->set_port = NULL;
1390                         recv_data->port = NULL;
1391                         recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_tls);
1392                         recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_ssl);
1393                         recv_data->default_port = 110;
1394                         recv_data->default_ssl_port = 995;
1395                         break;
1396                 case A_IMAP4:
1397                         recv_data->ssl_service = "imaps";
1398                         recv_data->tls_service = "imap";
1399                         recv_data->address = g_strdup(address);
1400                         recv_data->hostname_entry = GTK_ENTRY(wizard->recv_server);
1401                         recv_data->set_port = NULL;
1402                         recv_data->port = NULL;
1403                         recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_tls);
1404                         recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->recv_use_ssl);
1405                         recv_data->default_port = 143;
1406                         recv_data->default_ssl_port = 993;
1407                         break;
1408                 default:
1409                         cm_return_if_fail(FALSE);
1410                 }
1411                 auto_configure_service(recv_data);
1412         }
1413
1414         send_data = g_new0(AutoConfigureData, 1);
1415         send_data->configure_button = GTK_BUTTON(wizard->auto_configure_btn);
1416         send_data->cancel_button = GTK_BUTTON(wizard->auto_configure_cancel_btn);
1417         send_data->info_label = GTK_LABEL(wizard->auto_configure_lbl);
1418         send_data->cancel = send_cancel;
1419
1420         send_data->ssl_service = NULL;
1421         send_data->tls_service = "submission";
1422         send_data->address = g_strdup(address);
1423         send_data->hostname_entry = GTK_ENTRY(wizard->smtp_server);
1424         send_data->set_port = NULL;
1425         send_data->port = NULL;
1426         send_data->tls_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_use_tls);
1427         send_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl);
1428         send_data->default_port = 25;
1429         send_data->default_ssl_port = -1;
1430         send_data->auth_checkbtn = GTK_TOGGLE_BUTTON(wizard->smtp_auth);
1431
1432         auto_configure_service(send_data);
1433
1434         g_free(address);
1435 }
1436 #endif
1437
1438 static GtkWidget* recv_page (WizardWindow * wizard)
1439 {
1440         GtkWidget *table = gtk_table_new(1,1, FALSE);
1441         GtkWidget *vbox;
1442         GtkWidget *hbox;
1443         GtkWidget *hbox_spc;    
1444         GtkWidget *recv_table;
1445         GtkWidget *label;
1446 #ifdef USE_GNUTLS
1447         GtkWidget *button;
1448         GtkWidget *recv_cert_table;
1449 #endif
1450 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1451         GtkWidget *auto_configure_btn;
1452         GtkWidget *auto_configure_cancel_btn;
1453         GtkWidget *auto_configure_lbl;
1454 #endif
1455         GtkListStore *store;
1456         GtkTreeIter iter;
1457         gchar *text;
1458         gint index = 0;
1459
1460         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1461         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1462
1463         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1464         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1465
1466         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1467                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1468
1469         recv_table = gtk_table_new(4, 2, FALSE); 
1470
1471 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1472         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1473         auto_configure_btn = gtk_button_new_with_label(_("Auto-configure"));
1474         gtk_box_pack_start(GTK_BOX (hbox), auto_configure_btn, FALSE, FALSE, 0);
1475         auto_configure_cancel_btn = gtk_button_new_with_label(_("Cancel"));
1476         gtk_box_pack_start(GTK_BOX (hbox), auto_configure_cancel_btn, FALSE, FALSE, 0);
1477         auto_configure_lbl = gtk_label_new("");
1478         gtk_label_set_justify(GTK_LABEL(auto_configure_lbl), GTK_JUSTIFY_LEFT);
1479         gtk_box_pack_start(GTK_BOX (hbox), auto_configure_lbl, FALSE, FALSE, 0);
1480         gtk_widget_show(auto_configure_btn);
1481         gtk_widget_show(auto_configure_lbl);
1482         gtk_widget_show(hbox);
1483         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1484         wizard->auto_configure_lbl = auto_configure_lbl;
1485         wizard->auto_configure_btn = auto_configure_btn;
1486         wizard->auto_configure_cancel_btn = auto_configure_cancel_btn;
1487         g_signal_connect (G_OBJECT (auto_configure_btn), "clicked",
1488                           G_CALLBACK (auto_configure_cb), wizard);
1489         g_signal_connect (G_OBJECT (auto_configure_cancel_btn), "clicked",
1490                           G_CALLBACK (auto_configure_cb), wizard);
1491 #endif
1492         gtk_box_pack_start(GTK_BOX(vbox), recv_table, FALSE, FALSE, 0);
1493
1494
1495         label = gtk_label_new(_("<span weight=\"bold\">Server type:</span>"));
1496         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1497         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
1498         gtk_table_attach(GTK_TABLE(recv_table), label, 0,1,0,1, 
1499                          GTK_FILL, 0, VSPACING_NARROW, 0);
1500         wizard->recv_type = gtkut_sc_combobox_create(NULL, FALSE);
1501         store = GTK_LIST_STORE(gtk_combo_box_get_model(
1502                         GTK_COMBO_BOX(wizard->recv_type)));
1503
1504         COMBOBOX_ADD(store, _("POP3"), A_POP3);
1505         COMBOBOX_ADD(store, _("IMAP"), A_IMAP4);
1506         COMBOBOX_ADD(store, _("Local mbox file"), A_LOCAL);
1507
1508         switch(tmpl.recvtype) {
1509         case A_POP3: 
1510                 index = 0;
1511                 break;
1512         case A_IMAP4:
1513                 index = 1;
1514                 break;
1515         case A_LOCAL:
1516                 index = 2;
1517                 break;
1518         default:
1519                 index = 0;
1520         }
1521         gtk_combo_box_set_active(GTK_COMBO_BOX (wizard->recv_type), index);
1522         g_signal_connect(G_OBJECT(wizard->recv_type), "changed",
1523                          G_CALLBACK(wizard_protocol_changed),
1524                          wizard);
1525         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_type, 1,2,0,1, 
1526                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1527
1528         wizard->recv_label = gtk_label_new(_("<span weight=\"bold\">Server address:</span>"));
1529         gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);
1530         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1531         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_label, 0,1,1,2, 
1532                          GTK_FILL, 0, VSPACING_NARROW, 0);
1533         wizard->recv_server = gtk_entry_new();
1534         text = get_default_server(wizard, "pop");
1535         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1536         g_free(text);
1537         
1538         CLAWS_SET_TIP(wizard->recv_server,
1539                              _("You can specify the port number by appending it at the end: "
1540                                "\"mail.example.com:110\""));
1541         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_server, 1,2,1,2, 
1542                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1543         
1544         wizard->recv_username_label = gtk_label_new(_("<span weight=\"bold\">Username:</span>"));
1545         gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);
1546         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_username_label), TRUE);
1547         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_username_label, 0,1,2,3, 
1548                          GTK_FILL, 0, VSPACING_NARROW, 0);
1549         wizard->recv_username = gtk_entry_new();
1550         text = get_default_account(wizard);
1551         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
1552         g_free(text);
1553         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_username, 1,2,2,3, 
1554                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1555                          
1556         wizard->recv_password_label = gtk_label_new(_("Password:"));
1557         gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);
1558         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_password_label, 0,1,3,4, 
1559                          GTK_FILL, 0, VSPACING_NARROW, 0);
1560         wizard->recv_password = gtk_entry_new();
1561         gtk_entry_set_text(GTK_ENTRY(wizard->recv_password), tmpl.recvpass?tmpl.recvpass:"");
1562         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
1563         gtk_table_attach(GTK_TABLE(recv_table), wizard->recv_password, 1,2,3,4, 
1564                          GTK_EXPAND|GTK_FILL, 0, 0, 0); 
1565 #ifdef USE_GNUTLS
1566         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1567         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1568         wizard->recv_use_ssl = gtk_check_button_new_with_label(
1569                                         _("Use SSL to connect to receiving server"));
1570         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl),
1571                         tmpl.recvssl != 0);
1572         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_ssl, FALSE, FALSE, 0);
1573
1574         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1575         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1576         hbox_spc = gtk_hbox_new (FALSE, 0);
1577         gtk_widget_set_size_request (hbox_spc, 12, -1);
1578         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0); 
1579         wizard->recv_use_tls = gtk_check_button_new_with_label(
1580                                         _("Use SSL via STARTTLS"));
1581         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls),
1582                         tmpl.recvssl == 2);
1583         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_tls, FALSE, FALSE, 0);
1584         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, wizard->recv_use_tls);
1585
1586         recv_cert_table = gtk_table_new(3,3, FALSE);
1587         gtk_box_pack_start (GTK_BOX(vbox), recv_cert_table, FALSE, FALSE, 4);
1588         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1589         hbox_spc = gtk_hbox_new (FALSE, 0);
1590         gtk_widget_set_size_request (hbox_spc, 12, -1);
1591         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1592         label = gtk_label_new(_("Client SSL certificate (optional)"));
1593         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1594         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);    
1595         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
1596         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1597         hbox_spc = gtk_hbox_new (FALSE, 0);
1598         gtk_widget_set_size_request (hbox_spc, 12, -1);
1599         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1600         label = gtk_label_new(_("File"));
1601         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1602         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);      
1603         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 1, 1, 2, 
1604                          GTK_FILL, 0, VSPACING_NARROW, 0);
1605         wizard->recv_ssl_cert_file = gtk_entry_new();
1606         gtk_entry_set_text(GTK_ENTRY(wizard->recv_ssl_cert_file), tmpl.recvssl_cert?tmpl.recvssl_cert:"");
1607         gtk_table_attach(GTK_TABLE(recv_cert_table), wizard->recv_ssl_cert_file, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
1608         button = gtkut_get_browse_file_btn(_("Browse"));
1609         gtk_table_attach(GTK_TABLE(recv_cert_table), button, 2, 3, 1, 2, 
1610                          GTK_FILL, 0, VSPACING_NARROW, 0);
1611         g_signal_connect(G_OBJECT(button), "clicked",
1612                          G_CALLBACK(cert_browse_cb), wizard->recv_ssl_cert_file);
1613
1614         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1615         hbox_spc = gtk_hbox_new (FALSE, 0);
1616         gtk_widget_set_size_request (hbox_spc, 12, -1);
1617         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1618         label = gtk_label_new(_("Password"));
1619         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
1620         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1621         gtk_table_attach(GTK_TABLE(recv_cert_table), hbox, 0, 1, 2, 3, 
1622                          GTK_FILL, 0, VSPACING_NARROW, 0);
1623         wizard->recv_ssl_cert_pass = gtk_entry_new();
1624         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_ssl_cert_pass), FALSE);
1625         gtk_entry_set_text(GTK_ENTRY(wizard->recv_ssl_cert_pass), tmpl.recvssl_cert_pass?tmpl.recvssl_cert_pass:"");
1626         gtk_table_attach(GTK_TABLE(recv_cert_table), wizard->recv_ssl_cert_pass, 1, 2, 2, 3, GTK_FILL, 0, 0, 0);
1627         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, recv_cert_table); 
1628         wizard->recv_cert_table = recv_cert_table;
1629 #endif  
1630         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1631         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1632         wizard->recv_imap_subdir = gtk_entry_new();
1633         gtk_entry_set_text(GTK_ENTRY(wizard->recv_imap_subdir), tmpl.imapdir?tmpl.imapdir:"");
1634         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
1635         gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
1636         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_label, FALSE, FALSE, 0);
1637         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_subdir, TRUE, TRUE, 0);
1638         
1639         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1640         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1641         hbox_spc = gtk_hbox_new (FALSE, 0);
1642         gtk_widget_set_size_request (hbox_spc, 12, -1);
1643         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1644         wizard->subsonly_checkbtn = gtk_check_button_new_with_label(
1645                         _("Show only subscribed folders"));
1646         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn),
1647                         tmpl.subsonly);
1648         gtk_box_pack_start(GTK_BOX(hbox), wizard->subsonly_checkbtn, FALSE, FALSE, 0);
1649         
1650         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1651         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1652         wizard->no_imap_warning = gtk_label_new(_(
1653                           "<span weight=\"bold\">Warning: this version of Claws Mail\n"
1654                           "has been built without IMAP support.</span>"));
1655         gtk_label_set_use_markup(GTK_LABEL(wizard->no_imap_warning), TRUE);
1656         gtk_box_pack_start(GTK_BOX(hbox), wizard->no_imap_warning, FALSE, FALSE, 0);
1657
1658         return table;
1659 }
1660
1661 static void
1662 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
1663 {
1664         WizardWindow * wizard = (WizardWindow *)data;
1665         int current_page, num_pages;
1666         gboolean skip_mailbox_page = FALSE;
1667         gint protocol = combobox_get_active_data(GTK_COMBO_BOX(wizard->recv_type));
1668
1669         if (protocol == A_IMAP4) {
1670                 skip_mailbox_page = TRUE;
1671         }
1672
1673         num_pages = g_slist_length(wizard->pages);
1674
1675         current_page = gtk_notebook_get_current_page (
1676                                 GTK_NOTEBOOK(wizard->notebook));
1677         if (response == CANCEL)
1678         {
1679                 wizard->result = FALSE;
1680                 wizard->finished = TRUE;
1681                 gtk_widget_destroy (GTK_WIDGET(dialog));
1682         }
1683         else if (response == FINISHED)
1684         {
1685                 if (!wizard_write_config(wizard)) {
1686                         current_page = gtk_notebook_get_current_page (
1687                                         GTK_NOTEBOOK(wizard->notebook));
1688                         goto set_sens;
1689                 }
1690                 wizard->result = TRUE;
1691                 wizard->finished = TRUE;
1692                 gtk_widget_destroy (GTK_WIDGET(dialog));
1693         }
1694         else
1695         {
1696                 if (response == GO_BACK)
1697                 {
1698                         if (current_page > 0) {
1699                                 current_page--;
1700                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1701                                         /* mailbox */
1702                                         current_page--;
1703                                 }
1704                                 gtk_notebook_set_current_page (
1705                                         GTK_NOTEBOOK(wizard->notebook), 
1706                                         current_page);
1707                         }
1708                 }
1709                 else if (response == GO_FORWARD)
1710                 {
1711                         if (current_page < (num_pages-1)) {
1712                                 current_page++;
1713                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1714                                         /* mailbox */
1715                                         current_page++;
1716                                 }
1717                                 gtk_notebook_set_current_page (
1718                                         GTK_NOTEBOOK(wizard->notebook), 
1719                                         current_page);
1720                         }
1721                 }
1722 set_sens:
1723                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
1724                                 current_page > 0);
1725                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
1726                                 current_page < (num_pages - 1));
1727                 if (current_page == (num_pages -1)) {
1728                         gtk_dialog_set_response_sensitive (dialog, FINISHED, TRUE);
1729                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), FINISHED);
1730                 } else {
1731                         gtk_dialog_set_response_sensitive (dialog, FINISHED, FALSE);
1732                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), GO_FORWARD);
1733                 }
1734
1735         }
1736 }
1737
1738 static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
1739                                  gpointer data)
1740 {
1741         WizardWindow *wizard = (WizardWindow *)data;
1742         wizard->result = FALSE;
1743         wizard->finished = TRUE;
1744         
1745         return FALSE;
1746 }
1747
1748 #define PACK_WARNING(text) {                                            \
1749         label = gtk_label_new(text);                                    \
1750         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);                  \
1751         gtk_box_pack_end(GTK_BOX(widget), label, FALSE, FALSE, 0);      \
1752 }
1753
1754 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
1755         WizardWindow *wizard = g_new0(WizardWindow, 1);
1756         GtkWidget *page;
1757         GtkWidget *widget;
1758         GtkWidget *label;
1759         GtkWidget *scrolled_window;
1760         gchar     *text;
1761         GSList    *cur;
1762         gboolean   result;
1763         gint i = 0;
1764         wizard->mainwin = mainwin;
1765         wizard->create_mailbox = create_mailbox;
1766         
1767         gtk_widget_hide(mainwin->window);
1768         
1769         wizard_read_defaults();
1770         
1771         wizard->window = gtk_dialog_new_with_buttons (_("Claws Mail Setup Wizard"),
1772                         NULL, 0, 
1773                         GTK_STOCK_GO_BACK, GO_BACK,
1774                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
1775                         GTK_STOCK_SAVE, FINISHED,
1776                         GTK_STOCK_CANCEL, CANCEL,
1777                         NULL);
1778         gtk_widget_set_size_request(wizard->window, -1, 480);
1779         gtk_window_set_position(GTK_WINDOW(wizard->window), GTK_WIN_POS_CENTER);
1780
1781         g_signal_connect(wizard->window, "response", 
1782                           G_CALLBACK(wizard_response_cb), wizard);
1783         gtk_widget_realize(wizard->window);
1784         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
1785                         GO_FORWARD);
1786         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1787                         GO_BACK, FALSE);
1788         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1789                         GO_FORWARD, TRUE);
1790         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1791                         FINISHED, FALSE);
1792         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1793                         CANCEL, TRUE);
1794         
1795         wizard->notebook = gtk_notebook_new();
1796         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
1797         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
1798         gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(wizard->window))), 
1799                             wizard->notebook, TRUE, TRUE, 0);
1800         
1801         wizard->pages = NULL;
1802         
1803 /*welcome page: 0 */
1804         WELCOME_PAGE = i;
1805         page = create_page(wizard, _("Welcome to Claws Mail"));
1806         
1807         wizard->pages = g_slist_append(wizard->pages, page);
1808         widget = stock_pixmap_widget(wizard->window, 
1809                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1810
1811         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1812         
1813         text = g_strdup(_("Welcome to the Claws Mail setup wizard.\n\n"
1814                           "We will begin by defining some basic "
1815                           "information about you and your most common "
1816                           "mail options so that you can start to use "
1817                           "Claws Mail in less than five minutes."));
1818         widget = gtk_label_new(text);
1819         gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
1820         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1821         g_free(text);
1822
1823 /* user page: 1 */
1824         i++;
1825         USER_PAGE = i;
1826         widget = create_page (wizard, _("About You"));
1827         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1828         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1829                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1830         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1831
1832         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1833                                               user_page(wizard));
1834         PACK_WARNING(_("Bold fields must be completed"));
1835         
1836         wizard->pages = g_slist_append(wizard->pages, widget);
1837
1838 /* recv+auth page: 2 */
1839         i++;
1840         RECV_PAGE = i;
1841         widget = create_page (wizard, _("Receiving mail"));
1842         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1843         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1844                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1845         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1846
1847         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1848                                               recv_page(wizard));
1849         PACK_WARNING(_("Bold fields must be completed"));
1850         
1851         wizard->pages = g_slist_append(wizard->pages, widget);
1852
1853 /*smtp page: 3 */
1854         i++;
1855         SMTP_PAGE = i;
1856         widget = create_page (wizard, _("Sending mail"));
1857         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1858         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1859                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1860         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1861
1862         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1863                                               smtp_page(wizard));
1864         PACK_WARNING(_("Bold fields must be completed"));
1865         
1866         wizard->pages = g_slist_append(wizard->pages, widget);
1867
1868 /* mailbox page: 4 */
1869         if (create_mailbox) {
1870                 i++;
1871                 MAILBOX_PAGE = i;
1872                 widget = create_page (wizard, _("Saving mail on disk"));
1873                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1874                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1875                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1876                 gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1877
1878                 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1879                                               mailbox_page(wizard));
1880                 PACK_WARNING(_("Bold fields must be completed"));
1881         
1882                 wizard->pages = g_slist_append(wizard->pages, widget);
1883         }
1884
1885 /* done page: 6 */
1886         i++;
1887         DONE_PAGE = i;
1888         page = create_page(wizard, _("Configuration finished"));
1889         
1890         wizard->pages = g_slist_append(wizard->pages, page);
1891         widget = stock_pixmap_widget(wizard->window, 
1892                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1893
1894         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1895         
1896         text = g_strdup(_("Claws Mail is now ready.\n"
1897                           "Click Save to start."));
1898         widget = gtk_label_new(text);
1899         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1900         g_free(text);
1901
1902
1903         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
1904                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
1905                                           GTK_WIDGET(cur->data), NULL);
1906         }
1907         
1908         g_signal_connect(G_OBJECT(wizard->window), "delete_event",
1909                          G_CALLBACK(wizard_close_cb), wizard);
1910         gtk_widget_show_all (wizard->window);
1911
1912         gtk_widget_hide(wizard->recv_imap_label);
1913         gtk_widget_hide(wizard->recv_imap_subdir);
1914         gtk_widget_hide(wizard->subsonly_checkbtn);
1915 #if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
1916         gtk_widget_hide(wizard->auto_configure_cancel_btn);
1917 #endif
1918         wizard_protocol_change(wizard, tmpl.recvtype);
1919
1920         while (!wizard->finished)
1921                 gtk_main_iteration();
1922
1923         result = wizard->result;
1924         
1925         GTK_EVENTS_FLUSH();
1926
1927         gtk_widget_show(mainwin->window);
1928         g_free(wizard);
1929
1930         return result;
1931 }