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