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