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