2007-07-16 [paul] 2.10.0cvs29
[claws.git] / src / wizard.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 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/gtkwidget.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkbox.h>
33 #include <gtk/gtktable.h>
34 #include <gtk/gtkentry.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtknotebook.h>
37 #include <gtk/gtktogglebutton.h>
38 #include <gtk/gtkcheckbutton.h>
39 #include <gtk/gtk.h>
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <ctype.h>
45
46 #ifdef HAVE_CONFIG_H
47 #  include "config.h"
48 #endif
49
50 #include "utils.h"
51 #include "gtk/menu.h"
52 #include "plugin.h"
53 #include "account.h"
54 #include "prefs_account.h"
55 #include "mainwindow.h"
56 #include "stock_pixmap.h"
57 #include "setup.h"
58 #include "folder.h"
59 #include "alertpanel.h"
60 #ifdef USE_OPENSSL                      
61 #include "ssl.h"
62 #endif
63 #include "prefs_common.h"
64
65 typedef enum
66 {
67         GO_BACK,
68         GO_FORWARD,
69         CANCEL,
70         FINISHED
71 } PageNavigation;
72
73 int WELCOME_PAGE = -1;
74 int USER_PAGE = -1;
75 int SMTP_PAGE = -1;
76 int RECV_PAGE = -1;
77 int MAILBOX_PAGE = -1;
78 int DONE_PAGE = -1;
79
80 typedef struct
81 {
82         GtkWidget *window;
83         GSList    *pages;
84         GtkWidget *notebook;
85
86         MainWindow *mainwin;
87         
88         GtkWidget *email;
89         GtkWidget *full_name;
90         GtkWidget *organization;
91
92         GtkWidget *mailbox_name;
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_OPENSSL
113         GtkWidget *smtp_use_ssl;
114         GtkWidget *recv_use_ssl;
115         GtkWidget *smtp_use_tls;
116         GtkWidget *recv_use_tls;
117 #endif
118         
119         gboolean create_mailbox;
120         gboolean finished;
121         gboolean result;
122
123 } WizardWindow;
124
125 typedef struct _AccountTemplate {
126         gchar *name;
127         gchar *domain;
128         gchar *email;
129         gchar *organization;
130         gchar *smtpserver;
131         gboolean smtpauth;
132         gchar *smtpuser;
133         gchar *smtppass;
134         RecvProtocol recvtype;
135         gchar *recvserver;
136         gchar *recvuser;
137         gchar *recvpass;
138         gchar *imapdir;
139         gboolean subsonly;
140         gchar *mboxfile;
141         gchar *mailbox;
142         gboolean smtpssl;
143         gboolean recvssl;
144 } AccountTemplate;
145
146 static AccountTemplate tmpl;
147
148 static PrefParam template_params[] = {
149         {"name", "$USERNAME",
150          &tmpl.name, P_STRING, NULL, NULL, NULL},
151         {"domain", "$DEFAULTDOMAIN",
152          &tmpl.domain, P_STRING, NULL, NULL, NULL},
153         {"email", "$NAME_MAIL@$DOMAIN",
154          &tmpl.email, P_STRING, NULL, NULL, NULL},
155         {"organization", "",
156          &tmpl.organization, P_STRING, NULL, NULL, NULL},
157         {"smtpserver", "smtp.$DOMAIN",
158          &tmpl.smtpserver, P_STRING, NULL, NULL, NULL},
159         {"smtpauth", "FALSE",
160          &tmpl.smtpauth, P_BOOL, NULL, NULL, NULL},
161         {"smtpuser", "",
162          &tmpl.smtpuser, P_STRING, NULL, NULL, NULL},
163         {"smtppass", "",
164          &tmpl.smtppass, P_STRING, NULL, NULL, NULL},
165         {"recvtype", A_POP3,
166          &tmpl.recvtype, P_INT, NULL, NULL, NULL},
167         {"recvserver", "pop.$DOMAIN",
168          &tmpl.recvserver, P_STRING, NULL, NULL, NULL},
169         {"recvuser", "$LOGIN",
170          &tmpl.recvuser, P_STRING, NULL, NULL, NULL},
171         {"recvpass", "",
172          &tmpl.recvpass, P_STRING, NULL, NULL, NULL},
173         {"imapdir", "",
174          &tmpl.imapdir, P_STRING, NULL, NULL, NULL},
175         {"subsonly", "TRUE",
176          &tmpl.subsonly, P_BOOL, NULL, NULL, NULL},
177         {"mboxfile", "/var/mail/$LOGIN",
178          &tmpl.mboxfile, P_STRING, NULL, NULL, NULL},
179         {"mailbox", "Mail",
180          &tmpl.mailbox, P_STRING, NULL, NULL, NULL},
181         {"smtpssl", "0",
182          &tmpl.smtpssl, P_INT, NULL, NULL, NULL},
183         {"recvssl", "0",
184          &tmpl.recvssl, P_INT, NULL, NULL, NULL},
185         {NULL, NULL, NULL, P_INT, NULL, NULL, NULL}
186 };
187
188
189 static gchar *accountrc_tmpl =
190         "[AccountTemplate]\n"
191         "#you can use $DEFAULTDOMAIN here\n"
192         "#domain must be defined before the variables that use it\n"
193         "#by default, domain is extracted from the hostname\n"
194         "#domain=\n"
195         "\n"
196         "#you can use $USERNAME for name (this is the default)\n"
197         "#name=\n"
198         "\n"
199         "#you can use $LOGIN, $NAME_MAIL and $DOMAIN here \n"
200         "#$NAME_MAIL is the name without uppercase and with dots instead\n"
201         "#of spaces\n"
202         "#the default is $NAME_MAIL@$DOMAIN\n"
203         "#email=\n"
204         "\n"
205         "#you can use $DOMAIN here\n"
206         "#the default organization is empty\n"
207         "#organization=\n"
208         "\n"
209         "#you can use $DOMAIN here \n"
210         "#the default is stmp.$DOMAIN\n"
211         "#smtpserver=\n"
212         "\n"
213         "#Whether to use smtp authentication\n"
214         "#the default is 0 (no)\n"
215         "#smtpauth=\n"
216         "\n"
217         "#SMTP username\n"
218         "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
219         "#the default is empty (same as reception username)\n"
220         "#smtpuser=\n"
221         "\n"
222         "#SMTP password\n"
223         "#the default is empty (same as reception password)\n"
224         "#smtppass=\n"
225         "\n"
226         "#recvtype can be:\n"
227         "#0 for pop3\n"
228         "#3  for imap\n"
229         "#5  for a local mbox file\n"
230         "#recvtype=\n"
231         "\n"
232         "#you can use $DOMAIN here \n"
233         "#the default is {pop,imap}.$DOMAIN\n"
234         "#recvserver=\n"
235         "\n"
236         "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
237         "#default is $LOGIN\n"
238         "#recvuser=\n"
239         "\n"
240         "#default is empty\n"
241         "#recvpass=\n"
242         "\n"
243         "#imap dir if imap (relative to the home on the server)\n"
244         "#default is empty\n"
245         "#imapdir=\n"
246         "\n"
247         "#show subscribed folders only, if imap\n"
248         "#default is TRUE\n"
249         "#subsonly=\n"
250         "\n"
251         "#mbox file if local\n"
252         "#you can use $LOGIN here\n"
253         "#default is /var/mail/$LOGIN\n"
254         "#mboxfile=\n"
255         "\n"
256         "#mailbox name if pop3 or local\n"
257         "#relative path from the user's home\n"
258         "#default is \"Mail\"\n"
259         "#mailbox=\n"
260         "\n"
261         "#whether to use ssl on STMP connections\n"
262         "#default is 0, 1 is ssl, 2 is starttls\n"
263         "#smtpssl=\n"
264         "\n"
265         "#whether to use ssl on pop or imap connections\n"
266         "#default is 0, 1 is ssl, 2 is starttls\n"
267         "#recvssl=\n";
268
269 static gchar *wizard_get_default_domain_name(void)
270 {
271         static gchar *domain_name = NULL;
272         
273         if (domain_name == NULL) {
274                 domain_name = g_strdup(get_domain_name());
275                 if (strchr(domain_name, '.') != strrchr(domain_name, '.')
276                 && strlen(strchr(domain_name, '.')) > 6) {
277                         gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
278                         g_free(domain_name);
279                         domain_name = tmp;
280                 }
281         }
282         return domain_name;
283 }
284
285 static gchar *get_name_for_mail(void)
286 {
287         gchar *name = g_strdup(tmpl.name);
288         if (name == NULL)
289                 return NULL;
290         g_strdown(name);
291         while(strstr(name, " "))
292                 *strstr(name, " ")='.';
293         
294         return name;
295 }
296
297 #define PARSE_DEFAULT(str) {    \
298         gchar *tmp = NULL, *new = NULL; \
299         if (str != NULL) {      \
300                 tmp = g_strdup(str);    \
301                 if (strstr(str, "$USERNAME")) { \
302                         tmp = g_strdup(str);    \
303                         *strstr(tmp, "$USERNAME") = '\0';       \
304                         new = g_strconcat(tmp, g_get_real_name(),       \
305                                 strstr(str, "$USERNAME")+strlen("$USERNAME"),   \
306                                 NULL);  \
307                         g_free(tmp);    \
308                         g_free(str);    \
309                         str = new;      \
310                         new = NULL;     \
311                 }       \
312                 if (strstr(str, "$LOGIN")) {    \
313                         tmp = g_strdup(str);    \
314                         *strstr(tmp, "$LOGIN") = '\0';  \
315                         new = g_strconcat(tmp, g_get_user_name(),       \
316                                 strstr(str, "$LOGIN")+strlen("$LOGIN"),         \
317                                 NULL);  \
318                         g_free(tmp);    \
319                         g_free(str);    \
320                         str = new;      \
321                         new = NULL;     \
322                 }       \
323                 if (strstr(str, "$EMAIL")) {    \
324                         tmp = g_strdup(str);    \
325                         *strstr(tmp, "$EMAIL") = '\0';  \
326                         new = g_strconcat(tmp, tmpl.email,      \
327                                 strstr(str, "$EMAIL")+strlen("$EMAIL"),         \
328                                 NULL);  \
329                         g_free(tmp);    \
330                         g_free(str);    \
331                         str = new;      \
332                         new = NULL;     \
333                 }       \
334                 if (strstr(str, "$NAME_MAIL")) {        \
335                         tmp = g_strdup(str);    \
336                         *strstr(tmp, "$NAME_MAIL") = '\0';      \
337                         new = g_strconcat(tmp, get_name_for_mail(),     \
338                                 strstr(str, "$NAME_MAIL")+strlen("$NAME_MAIL"),         \
339                                 NULL);  \
340                         g_free(tmp);    \
341                         g_free(str);    \
342                         str = new;      \
343                         new = NULL;     \
344                 }       \
345                 if (strstr(str, "$DEFAULTDOMAIN")) {    \
346                         tmp = g_strdup(str);    \
347                         *strstr(tmp, "$DEFAULTDOMAIN") = '\0';  \
348                         new = g_strconcat(tmp, wizard_get_default_domain_name(),        \
349                                 strstr(str, "$DEFAULTDOMAIN")+strlen("$DEFAULTDOMAIN"),         \
350                                 NULL);  \
351                         g_free(tmp);    \
352                         g_free(str);    \
353                         str = new;      \
354                         new = NULL;     \
355                 }       \
356                 if (strstr(str, "$DOMAIN")) {   \
357                         tmp = g_strdup(str);    \
358                         *strstr(tmp, "$DOMAIN") = '\0'; \
359                         new = g_strconcat(tmp, tmpl.domain,     \
360                                 strstr(str, "$DOMAIN")+strlen("$DOMAIN"),       \
361                                 NULL);  \
362                         g_free(tmp);    \
363                         g_free(str);    \
364                         str = new;      \
365                         new = NULL;     \
366                 }       \
367         }       \
368 }
369 static void wizard_read_defaults(void)
370 {
371         gchar *rcpath;
372
373         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "accountrc.tmpl", NULL);
374         if (!is_file_exist(rcpath)) {
375                 str_write_to_file(accountrc_tmpl, rcpath);
376         }
377
378         prefs_read_config(template_params, "AccountTemplate", rcpath, NULL);
379
380         PARSE_DEFAULT(tmpl.domain);
381         PARSE_DEFAULT(tmpl.name);
382         PARSE_DEFAULT(tmpl.email);
383         PARSE_DEFAULT(tmpl.organization);
384         PARSE_DEFAULT(tmpl.smtpserver);
385         PARSE_DEFAULT(tmpl.smtpuser);
386         PARSE_DEFAULT(tmpl.smtppass);
387         PARSE_DEFAULT(tmpl.recvserver);
388         PARSE_DEFAULT(tmpl.recvuser);
389         PARSE_DEFAULT(tmpl.recvpass);
390         PARSE_DEFAULT(tmpl.imapdir);
391         PARSE_DEFAULT(tmpl.mboxfile);
392         PARSE_DEFAULT(tmpl.mailbox);
393 /*
394         printf("defaults:"
395         "%s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s, %s, %d, %d\n",
396         tmpl.name,tmpl.domain,tmpl.email,tmpl.organization,tmpl.smtpserver,
397         tmpl.recvtype,tmpl.recvserver,tmpl.recvuser,tmpl.recvpass,
398         tmpl.imapdir,tmpl.mboxfile,tmpl.mailbox,tmpl.smtpssl,tmpl.recvssl);
399 */
400         g_free(rcpath);
401 }
402
403 static void initialize_fonts(WizardWindow *wizard)
404 {
405         GtkWidget *widget = wizard->email;
406         gint size = pango_font_description_get_size(
407                         widget->style->font_desc)
408                       /PANGO_SCALE;
409         gchar *tmp, *new;
410         
411         tmp = g_strdup(prefs_common.textfont);
412         if (strrchr(tmp, ' ')) {
413                 *(strrchr(tmp, ' ')) = '\0';
414                 new = g_strdup_printf("%s %d", tmp, size);
415                 g_free(prefs_common.textfont);
416                 prefs_common.textfont = new;
417         }
418         g_free(tmp);
419         
420         tmp = g_strdup(prefs_common.smallfont);
421         if (strrchr(tmp, ' ')) {
422                 *(strrchr(tmp, ' ')) = '\0';
423                 new = g_strdup_printf("%s %d", tmp, size);
424                 g_free(prefs_common.smallfont);
425                 prefs_common.smallfont = new;
426         }
427         g_free(tmp);
428         
429         tmp = g_strdup(prefs_common.normalfont);
430         if (strrchr(tmp, ' ')) {
431                 *(strrchr(tmp, ' ')) = '\0';
432                 new = g_strdup_printf("%s %d", tmp, size);
433                 g_free(prefs_common.normalfont);
434                 prefs_common.normalfont = new;
435         }
436         g_free(tmp);
437 }
438
439 #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"
440 #define FACE "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAM1BMVEUAAAAcJCI\n\
441  ONl1JUi0+Z4daY2NZciPabV9ykS5kj6Wsl2ybmZOBsMjZxK2wzN3Pzczs7OsCAGN0AAAAAXRSTlM\n\
442  AQObYZgAAAAFiS0dEAIgFHUgAAAIVSURBVEjH1ZbtlqMgDIaFECoGhPu/2s0b0Lais/NzN6d1OJ7\n\
443  3yReQzrL8B5Zy3rvl9At52Pf2tv1vSMjtYj8jaa8XUyI/yn3YD6sigj/2Tf5Bn069MIsTPHvx/t5\n\
444  /3rU/6JCIY3YwGe26r/cwUfE3cFe5T28L0K5rJAUHEeYAQxs8DHojjk3M9wECU4xxjXisI8RA0gy\n\
445  oczJZJOjxiTFZVTchAnIRJrgdmEGDyFfAI3UuG5FmYTkR9RDrIC4H0SqV4pzpEcUp0HNLjwBv+jA\n\
446  dikUE5g9iBvzmu3sH2oDk4lnHd829+2Q9gj6kDqDPg7hsGwBzH02fE3ZCt6ZHmlNKIMjMeRwra5I\n\
447  ecgNoBnLGPmzaHPJIwLY8Sq2M/tLUJfj0QcqmfVXAdLSStIYF8dzWjBBb2VgvDa4mO9oc651OiUo\n\
448  BEKbZokdPATF9E9oKAjQJcJOniaPXrVZRAnVWaqIyqRoNC8ZJvgCcW8XN39RqxVP1rS8Yd4WnCdN\n\
449  aRTo2jJRDbg3vtCpEUGffgDPhqKDaSuVqYtOplFIvIcx3HUI5/MuIWl6vKyBjNlqEru8hbFXqBPA\n\
450  5TpHGIUZOePeaIyzfQ/g9Xg0opU1AvdfXM9floYhv92pPAE96OZtkPV8eivgQi9RTfwPUU36I26n\n\
451  Hy+WuCJzAT7efMSeA1TNf2/VugDz+dN139xfA5ffxGZDD+MvcP/uvyB80wzZ76wbz8gAAAABJRU5\n\
452  ErkJggg=="
453
454 static void write_welcome_email(WizardWindow *wizard)
455 {
456         gchar buf_date[64];
457         gchar *head=NULL;
458         gchar *body=NULL;
459         gchar *msg=NULL;
460         const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name));
461         Folder *folder = folder_find_from_path(mailbox);
462         FolderItem *inbox = folder ? folder->inbox:NULL;
463         gchar *file = get_tmp_file();
464         gchar enc_from_name[BUFFSIZE], enc_to_name[BUFFSIZE], enc_subject[BUFFSIZE];
465         
466         get_rfc822_date(buf_date, sizeof(buf_date));
467
468         conv_encode_header_full(enc_subject, sizeof(enc_subject), 
469                         Q_("Welcome Mail Subject|Welcome to Claws Mail"),
470                         strlen("Subject: "), FALSE, CS_INTERNAL);
471         conv_encode_header_full(enc_to_name, sizeof(enc_to_name), 
472                         gtk_entry_get_text(GTK_ENTRY(wizard->full_name)),
473                         strlen("To: "), TRUE, CS_INTERNAL);
474         conv_encode_header_full(enc_from_name, sizeof(enc_from_name), 
475                         _("The Claws Mail Team"),
476                         strlen("From: "), TRUE, CS_INTERNAL);
477
478         head = g_strdup_printf(
479                 "From: %s <%s>\n"
480                 "To: %s <%s>\n"
481                 "Date: %s\n"
482                 "Subject: %s\n"
483                 "X-Face: %s\n"
484                 "Face: %s\n"
485                 "Content-Type: text/plain; charset=UTF-8\n",
486                 enc_from_name,
487                 USERS_ML_ADDR,
488                 enc_to_name,
489                 gtk_entry_get_text(GTK_ENTRY(wizard->email)),
490                 buf_date, enc_subject, XFACE, FACE);
491         body = g_strdup_printf(
492                 _("\n"
493                 "Welcome to Claws Mail\n"
494                 "---------------------\n"
495                 "\n"
496                 "Now that you have set up your account you can fetch your\n"
497                 "mail by clicking the 'Get Mail' button at the left of the\n"
498                 "toolbar.\n"
499                 "\n"
500                 "Claws Mail has lots of extra features accessible via plugins,\n"
501                 "like anti-spam filtering and learning (via the Bogofilter or\n"
502                 "SpamAssassin plugins), privacy protection (via PGP/Mime), an RSS\n"
503                 "aggregator, a calendar, and much more. You can load them from\n"
504                 "the menu entry '/Configuration/Plugins'.\n"
505                 "\n"
506                 "You can change your Account Preferences by using the menu\n"
507                 "entry '/Configuration/Preferences for current account'\n"
508                 "and change the general Preferences by using\n"
509                 "'/Configuration/Preferences'.\n"
510                 "\n"
511                 "You can find further information in the Claws Mail manual,\n"
512                 "which can be accessed by using the menu entry '/Help/Manual'\n"
513                 "or online at the URL given below.\n"
514                 "\n"
515                 "Useful URLs\n"
516                 "-----------\n"
517                 "Homepage:      <%s>\n"
518                 "Manual:        <%s>\n"
519                 "FAQ:          <%s>\n"
520                 "Themes:        <%s>\n"
521                 "Mailing Lists: <%s>\n"
522                 "\n"
523                 "LICENSE\n"
524                 "-------\n"
525                 "Claws Mail is free software, released under the terms\n"
526                 "of the GNU General Public License, version 3 or later, as\n"
527                 "published by the Free Software Foundation, 51 Franklin Street,\n"
528                 "Fifth Floor, Boston, MA 02110-1301, USA. The license can be\n"
529                 "found at <%s>.\n"
530                 "\n"
531                 "DONATIONS\n"
532                 "---------\n"
533                 "If you wish to donate to the Claws Mail project you can do\n"
534                 "so at <%s>.\n\n"),
535                 HOMEPAGE_URI, MANUAL_URI, FAQ_URI, THEMES_URI, MAILING_LIST_URI,
536                 GPL_URI, DONATE_URI);
537         
538         msg = g_strconcat(head, body, NULL);
539
540         if (inbox && inbox->total_msgs == 0
541          && str_write_to_file(msg, file) >= 0) {
542                 MsgFlags flags = { MSG_UNREAD|MSG_NEW, 0};
543                 folder_item_add_msg(inbox, file, &flags, FALSE);
544         }
545         g_free(head);
546         g_free(body);
547         g_free(msg);
548         g_unlink(file);
549 }
550 #undef XFACE
551
552 static gboolean wizard_write_config(WizardWindow *wizard)
553 {
554         static gboolean mailbox_ok = FALSE;
555         PrefsAccount *prefs_account = prefs_account_new();
556         GList *account_list = NULL;
557         GtkWidget *menu, *menuitem;
558         gchar *smtp_server, *recv_server;
559         gchar *tmp;
560         gint smtp_port, recv_port;
561 #ifdef USE_OPENSSL                      
562         SSLType smtp_ssl_type, recv_ssl_type;
563 #endif
564
565         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
566         menuitem = gtk_menu_get_active(GTK_MENU(menu));
567         prefs_account->protocol = GPOINTER_TO_INT
568                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
569         
570         
571         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4 && 
572             !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)))) {
573                 alertpanel_error(_("Please enter the mailbox name."));
574                 g_free(prefs_account);
575                 gtk_notebook_set_current_page (
576                         GTK_NOTEBOOK(wizard->notebook), 
577                         MAILBOX_PAGE);
578                 return FALSE;
579         }
580
581         if (!mailbox_ok) {
582                 if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
583                         mailbox_ok = setup_write_mailbox_path(wizard->mainwin, 
584                                         gtk_entry_get_text(
585                                                 GTK_ENTRY(wizard->mailbox_name)));
586                 } else
587                         mailbox_ok = TRUE;
588         }
589
590         if (!mailbox_ok) {
591                 /* alertpanel done by setup_write_mailbox_path */
592                 g_free(prefs_account);
593                 gtk_notebook_set_current_page (
594                         GTK_NOTEBOOK(wizard->notebook), 
595                         MAILBOX_PAGE);
596                 return FALSE;
597         }
598         
599         if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->full_name)))
600         ||  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->email)))) {
601                 alertpanel_error(_("Please enter your name and email address."));
602                 g_free(prefs_account);
603                 gtk_notebook_set_current_page (
604                         GTK_NOTEBOOK(wizard->notebook), 
605                         USER_PAGE);
606                 return FALSE;
607         }
608         
609         if (prefs_account->protocol != A_LOCAL) {
610                 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)))
611                 ||  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
612                         alertpanel_error(_("Please enter your receiving server "
613                                            "and username."));
614                         g_free(prefs_account);
615                         gtk_notebook_set_current_page (
616                                 GTK_NOTEBOOK(wizard->notebook), 
617                                 RECV_PAGE);
618                         return FALSE;
619                 }
620         } else {
621                 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
622                         alertpanel_error(_("Please enter your username."));
623                         g_free(prefs_account);
624                         gtk_notebook_set_current_page (
625                                 GTK_NOTEBOOK(wizard->notebook), 
626                                 RECV_PAGE);
627                         return FALSE;
628                 }
629         }
630         
631         if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)))) {
632                 alertpanel_error(_("Please enter your SMTP server."));
633                 g_free(prefs_account);
634                 gtk_notebook_set_current_page (
635                         GTK_NOTEBOOK(wizard->notebook), 
636                         SMTP_PAGE);
637                 return FALSE;
638         }
639
640         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
641                 if (prefs_account->protocol == A_LOCAL
642                 &&  !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)))) {
643                         alertpanel_error(_("Please enter your SMTP username."));
644                         g_free(prefs_account);
645                         gtk_notebook_set_current_page (
646                                 GTK_NOTEBOOK(wizard->notebook), 
647                                 SMTP_PAGE);
648                         return FALSE;           
649                 } /* if it's not local we'll use the reception server */
650         }
651
652         if (prefs_account->protocol != A_LOCAL)
653                 prefs_account->account_name = g_strdup_printf("%s@%s",
654                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
655                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
656         else
657                 prefs_account->account_name = g_strdup_printf("%s",
658                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
659
660         recv_server = g_strdup(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
661         smtp_server = g_strdup(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)));
662
663         if (prefs_account->protocol != A_LOCAL && strstr(recv_server, ":")) {
664                 recv_port = atoi(strstr(recv_server, ":")+1);
665                 *(strstr(recv_server, ":")) = '\0';
666                 if (prefs_account->protocol == A_IMAP4) {
667                         prefs_account->set_imapport = TRUE;
668                         prefs_account->imapport = recv_port;
669                 } else if (prefs_account->protocol == A_POP3) {
670                         prefs_account->set_popport = TRUE;
671                         prefs_account->popport = recv_port;
672                 }
673         }
674         if (strstr(smtp_server, ":")) {
675                 smtp_port = atoi(strstr(smtp_server, ":")+1);
676                 *(strstr(smtp_server, ":")) = '\0';
677                 prefs_account->set_smtpport = TRUE;
678                 prefs_account->smtpport = smtp_port;
679         }
680         
681         prefs_account->name = g_strdup(
682                                 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)));
683         prefs_account->address = g_strdup(
684                                 gtk_entry_get_text(GTK_ENTRY(wizard->email)));
685         prefs_account->organization = g_strdup(
686                                 gtk_entry_get_text(GTK_ENTRY(wizard->organization)));
687         prefs_account->smtp_server = g_strdup(smtp_server);
688
689         tmp = g_path_get_basename(gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)));
690         prefs_account->inbox = g_strdup_printf("#mh/%s/inbox",
691                         (tmp && !strcmp("Mail", tmp))?_("Mailbox"):tmp);
692         g_free(tmp);
693         prefs_account->local_inbox = g_strdup(prefs_account->inbox);
694
695         if (prefs_account->protocol != A_LOCAL)
696                 prefs_account->recv_server = g_strdup(recv_server);
697         else
698                 prefs_account->local_mbox = g_strdup(recv_server);
699
700         g_free(recv_server);
701         g_free(smtp_server);
702
703         prefs_account->userid = g_strdup(
704                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
705         prefs_account->passwd = g_strdup(
706                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)));
707
708         prefs_account->smtp_userid = g_strdup(
709                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)));
710         prefs_account->smtp_passwd = g_strdup(
711                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_password)));
712         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
713                 prefs_account->use_smtp_auth = TRUE;
714         }
715
716 #ifdef USE_OPENSSL
717         smtp_ssl_type = SSL_NONE;
718         recv_ssl_type = SSL_NONE;       
719
720         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl))) {
721                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls)))
722                         smtp_ssl_type = SSL_STARTTLS;
723                 else
724                         smtp_ssl_type = SSL_TUNNEL;
725         }
726         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
727                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls)))
728                         recv_ssl_type = SSL_STARTTLS;
729                 else
730                         recv_ssl_type = SSL_TUNNEL;
731         }
732
733         prefs_account->ssl_smtp = smtp_ssl_type;
734
735         if (prefs_account->protocol == A_IMAP4)
736                 prefs_account->ssl_imap = recv_ssl_type;
737         else
738                 prefs_account->ssl_pop = recv_ssl_type;
739
740 #endif
741         if (prefs_account->protocol == A_IMAP4) {
742                 gchar *directory = gtk_editable_get_chars(
743                         GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
744                 if (directory && strlen(directory)) {
745                         prefs_account->imap_dir = g_strdup(directory);
746                 }
747                 prefs_account->imap_subsonly = 
748                         gtk_toggle_button_get_active(
749                                 GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn));
750                 g_free(directory);
751         }
752
753         account_list = g_list_append(account_list, prefs_account);
754         prefs_account_write_config_all(account_list);
755         prefs_account_free(prefs_account);
756         account_read_config_all();
757
758         initialize_fonts(wizard);
759         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4)
760                 write_welcome_email(wizard);
761         
762 #ifndef G_OS_WIN32 
763         plugin_load_standard_plugins();
764 #endif
765         return TRUE;
766 }
767
768 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
769 {
770         GtkWidget *w;
771         GtkWidget *vbox;
772         GtkWidget *hbox;
773         GtkWidget *image;
774         char *title_string;
775
776         vbox = gtk_vbox_new (FALSE, 6);
777         gtk_container_set_border_width  (GTK_CONTAINER(vbox), 10);
778
779         /* create the titlebar */
780         hbox = gtk_hbox_new (FALSE, 12);
781         image = stock_pixmap_widget(wizard->window, 
782                                 STOCK_PIXMAP_CLAWS_MAIL_ICON);
783         gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
784         title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
785         w = gtk_label_new (title_string);
786         gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
787         g_free (title_string);
788         gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
789
790         /* pack the titlebar */
791         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
792
793         /* pack the separator */
794         gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
795
796         /* pack space */
797         w = gtk_alignment_new (0, 0, 0, 0);
798         gtk_widget_set_size_request (w, 0, 6);
799         gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
800
801         return vbox;
802 }
803
804 #define PACK_BOX(hbox,text,entry) {                                     \
805         GtkWidget *label = gtk_label_new(text);                         \
806         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);               \
807         if (GTK_IS_MISC(label))                                         \
808                 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);        \
809         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);      \
810         gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);        \
811 }
812
813 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
814 {
815         if (!strcmp(type, "smtp")) {
816                 if (!tmpl.smtpserver || !strlen(tmpl.smtpserver))
817                         return g_strconcat(type, ".", tmpl.domain, NULL);
818                 else 
819                         return g_strdup(tmpl.smtpserver);
820         } else {
821                 if (!tmpl.recvserver || !strlen(tmpl.recvserver))
822                         return g_strconcat(type, ".", tmpl.domain, NULL);
823                 else 
824                         return g_strdup(tmpl.recvserver);
825         }
826 }
827
828 static gchar *get_default_account(WizardWindow * wizard)
829 {
830         gchar *result = NULL;
831         
832         if (!tmpl.recvuser || !strlen(tmpl.recvuser)) {
833                 result = gtk_editable_get_chars(
834                                 GTK_EDITABLE(wizard->email), 0, -1);
835
836                 if (strstr(result, "@")) {
837                         *(strstr(result,"@")) = '\0';
838                 } 
839         } else {
840                 result = g_strdup(tmpl.recvuser);
841         }
842         return result;
843 }
844
845 static gchar *get_default_smtp_account(WizardWindow * wizard)
846 {
847         gchar *result = NULL;
848         
849         if (!tmpl.smtpuser || !strlen(tmpl.smtpuser)) {
850                 return g_strdup("");
851         } else {
852                 result = g_strdup(tmpl.smtpuser);
853         }
854         return result;
855 }
856
857 static void wizard_email_changed(GtkWidget *widget, gpointer data)
858 {
859         WizardWindow *wizard = (WizardWindow *)data;
860         RecvProtocol protocol;
861         gchar *text;
862         protocol = GPOINTER_TO_INT
863                 (g_object_get_data(G_OBJECT(wizard->recv_type), MENU_VAL_ID));
864         
865         text = get_default_server(wizard, "smtp");
866         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
867         g_free(text);
868
869         text = get_default_account(wizard);
870         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
871         g_free(text);
872
873         if (protocol == A_POP3) {
874                 text = get_default_server(wizard, "pop");
875                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
876                 g_free(text);
877         } else if (protocol == A_IMAP4) {
878                 text = get_default_server(wizard, "imap");
879                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
880                 g_free(text);
881         } else if (protocol == A_LOCAL) {
882                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
883         }
884         
885 }
886
887 static GtkWidget* user_page (WizardWindow * wizard)
888 {
889         GtkWidget *table = gtk_table_new(1,1, FALSE);
890         GtkWidget *vbox;
891         GtkWidget *hbox;
892         
893         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
894         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
895
896         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
897         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
898
899         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
900                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
901
902         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
903         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
904         wizard->full_name = gtk_entry_new();
905         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), tmpl.name?tmpl.name:"");
906         PACK_BOX(hbox, _("<span weight=\"bold\">Your name:</span>"),
907                  wizard->full_name);
908         
909         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
910         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
911         wizard->email = gtk_entry_new();
912         gtk_entry_set_text(GTK_ENTRY(wizard->email), tmpl.email?tmpl.email:"");
913         PACK_BOX(hbox, _("<span weight=\"bold\">Your email address:</span>"),
914                  wizard->email);
915         
916         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
917         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);      
918         wizard->organization = gtk_entry_new();
919         gtk_entry_set_text(GTK_ENTRY(wizard->organization), tmpl.organization?tmpl.organization:"");
920         PACK_BOX(hbox, _("Your organization:"), wizard->organization);
921         
922         g_signal_connect(G_OBJECT(wizard->email), "changed",
923                          G_CALLBACK(wizard_email_changed),
924                          wizard);
925         return table;
926 }
927
928 static GtkWidget* mailbox_page (WizardWindow * wizard)
929 {
930         GtkWidget *table = gtk_table_new(1,1, FALSE);
931         GtkWidget *vbox;
932         GtkWidget *hbox;
933         GtkTooltips *tips = gtk_tooltips_new();
934
935         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
936         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
937
938         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
939         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
940
941         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
942                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
943
944         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
945         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
946         wizard->mailbox_name = gtk_entry_new();
947         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), tmpl.mailbox?tmpl.mailbox:"");
948
949         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->mailbox_name,
950                              _("You can also specify an absolute path, for example: "
951                                "\"/home/john/Documents/Mail\""),
952                              NULL);
953
954         PACK_BOX(hbox, _("<span weight=\"bold\">Mailbox name:</span>"),
955                  wizard->mailbox_name);
956         
957         return table;
958 }
959
960 static void smtp_auth_changed (GtkWidget *btn, gpointer data)
961 {
962         WizardWindow *wizard = (WizardWindow *)data;
963         gboolean do_auth = gtk_toggle_button_get_active(
964                 GTK_TOGGLE_BUTTON(wizard->smtp_auth));
965         gtk_widget_set_sensitive(wizard->smtp_username, do_auth);
966         gtk_widget_set_sensitive(wizard->smtp_username_label, do_auth);
967         gtk_widget_set_sensitive(wizard->smtp_password, do_auth);
968         gtk_widget_set_sensitive(wizard->smtp_password_label, do_auth);
969 }
970
971 static GtkWidget* smtp_page (WizardWindow * wizard)
972 {
973         GtkWidget *table = gtk_table_new(1, 1, FALSE);
974         GtkWidget *vbox;
975         GtkWidget *hbox;
976         GtkTooltips *tips = gtk_tooltips_new();
977         gchar *text;
978         
979         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
980         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
981
982         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
983         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
984
985         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
986                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
987
988         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
989         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
990         wizard->smtp_server = gtk_entry_new();
991         text = get_default_server(wizard, "smtp");
992         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
993         g_free(text);
994
995         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->smtp_server,
996                              _("You can specify the port number by appending it at the end: "
997                                "\"mail.example.com:25\""),
998                              NULL);
999
1000         PACK_BOX(hbox, _("<span weight=\"bold\">SMTP server address:</span>"),
1001                  wizard->smtp_server);
1002
1003
1004         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1005         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1006         wizard->smtp_auth = gtk_check_button_new_with_label(
1007                                         _("Use authentication"));
1008         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth),
1009                         tmpl.smtpauth);
1010         g_signal_connect(G_OBJECT(wizard->smtp_auth), "toggled",
1011                          G_CALLBACK(smtp_auth_changed),
1012                          wizard);
1013         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_auth, FALSE, FALSE, 0);
1014
1015         text = get_default_smtp_account(wizard);
1016
1017         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1018         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1019         wizard->smtp_username = gtk_entry_new();
1020         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_username), text);
1021         g_free(text);
1022         wizard->smtp_username_label = gtk_label_new(_("SMTP username:\n"
1023                                         "<span size=\"small\">(empty to use the same as receive)</span>"));
1024         gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_username_label), TRUE);
1025         if (GTK_IS_MISC(wizard->smtp_username_label))                                                 
1026                 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_username_label), 1, 0.5);        
1027         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_username_label, FALSE, FALSE, 0);
1028         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_username, TRUE, TRUE, 0);
1029
1030         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1031         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1032         wizard->smtp_password = gtk_entry_new();
1033         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_password), tmpl.smtppass?tmpl.smtppass:""); 
1034         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_password), FALSE);
1035         wizard->smtp_password_label = gtk_label_new(_("SMTP password:\n"
1036                                         "<span size=\"small\">(empty to use the same as receive)</span>"));
1037         gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_password_label), TRUE);
1038         if (GTK_IS_MISC(wizard->smtp_password_label))                                                 
1039                 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_password_label), 1, 0.5);        
1040         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_password_label, FALSE, FALSE, 0);
1041         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_password, TRUE, TRUE, 0);
1042 #ifdef USE_OPENSSL
1043         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1044         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1045         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
1046                                         _("Use SSL to connect to SMTP server"));
1047         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl),
1048                         tmpl.smtpssl != 0);
1049         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_ssl, FALSE, FALSE, 0);
1050
1051         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1052         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1053         wizard->smtp_use_tls = gtk_check_button_new_with_label(
1054                                         _("Use SSL via STARTTLS"));
1055         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls),
1056                         tmpl.smtpssl == 2);
1057         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_tls, FALSE, FALSE, 0);
1058         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, wizard->smtp_use_tls);
1059 #endif
1060         smtp_auth_changed(NULL, wizard);
1061         return table;
1062 }
1063
1064 static void wizard_protocol_change(WizardWindow *wizard, RecvProtocol protocol)
1065 {
1066         gchar *text;
1067         
1068         if (protocol == A_POP3) {
1069                 text = get_default_server(wizard, "pop");
1070                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1071                 gtk_widget_hide(wizard->recv_imap_label);
1072                 gtk_widget_hide(wizard->recv_imap_subdir);
1073                 gtk_widget_hide(wizard->subsonly_checkbtn);
1074                 gtk_widget_show(wizard->recv_username);
1075                 gtk_widget_show(wizard->recv_password);
1076                 gtk_widget_show(wizard->recv_username_label);
1077                 gtk_widget_show(wizard->recv_password_label);
1078                 gtk_widget_hide(wizard->no_imap_warning);
1079 #ifdef USE_OPENSSL
1080                 gtk_widget_show(wizard->recv_use_ssl);
1081                 gtk_widget_show(wizard->recv_use_tls);
1082 #endif
1083                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1084                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1085                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1086                 g_free(text);
1087         } else if (protocol == A_IMAP4) {
1088 #ifdef HAVE_LIBETPAN
1089                 text = get_default_server(wizard, "imap");
1090                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1091                 gtk_widget_show(wizard->recv_imap_label);
1092                 gtk_widget_show(wizard->recv_imap_subdir);
1093                 gtk_widget_show(wizard->subsonly_checkbtn);
1094                 gtk_widget_show(wizard->recv_username);
1095                 gtk_widget_show(wizard->recv_password);
1096                 gtk_widget_show(wizard->recv_username_label);
1097                 gtk_widget_show(wizard->recv_password_label);
1098                 gtk_widget_hide(wizard->no_imap_warning);
1099 #ifdef USE_OPENSSL
1100                 gtk_widget_show(wizard->recv_use_ssl);
1101                 gtk_widget_show(wizard->recv_use_tls);
1102 #endif
1103                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1104                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1105                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1106                 g_free(text);
1107 #else
1108                 gtk_widget_hide(wizard->recv_imap_label);
1109                 gtk_widget_hide(wizard->recv_imap_subdir);
1110                 gtk_widget_hide(wizard->subsonly_checkbtn);
1111                 gtk_widget_hide(wizard->recv_username);
1112                 gtk_widget_hide(wizard->recv_password);
1113                 gtk_widget_hide(wizard->recv_username_label);
1114                 gtk_widget_hide(wizard->recv_password_label);
1115                 gtk_widget_show(wizard->no_imap_warning);
1116 #ifdef USE_OPENSSL
1117                 gtk_widget_hide(wizard->recv_use_ssl);
1118                 gtk_widget_hide(wizard->recv_use_tls);
1119 #endif
1120                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, FALSE);
1121 #endif
1122         } else if (protocol == A_LOCAL) {
1123                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
1124                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Local mailbox:</span>"));
1125                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1126                 gtk_widget_hide(wizard->no_imap_warning);
1127                 gtk_widget_hide(wizard->recv_imap_label);
1128                 gtk_widget_hide(wizard->recv_imap_subdir);
1129                 gtk_widget_hide(wizard->subsonly_checkbtn);
1130                 gtk_widget_hide(wizard->recv_username);
1131                 gtk_widget_hide(wizard->recv_password);
1132                 gtk_widget_hide(wizard->recv_username_label);
1133                 gtk_widget_hide(wizard->recv_password_label);
1134 #ifdef USE_OPENSSL
1135                 gtk_widget_hide(wizard->recv_use_ssl);
1136                 gtk_widget_hide(wizard->recv_use_tls);
1137 #endif
1138                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1139         }
1140 }
1141
1142 static void wizard_protocol_changed(GtkMenuItem *menuitem, gpointer data)
1143 {
1144         WizardWindow *wizard = (WizardWindow *)data;
1145         RecvProtocol protocol;
1146         protocol = GPOINTER_TO_INT
1147                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1148
1149         wizard_protocol_change(wizard, protocol);       
1150 }
1151
1152 static GtkWidget* recv_page (WizardWindow * wizard)
1153 {
1154         GtkWidget *table = gtk_table_new(1,1, FALSE);
1155         GtkWidget *menu = gtk_menu_new();
1156         GtkWidget *menuitem;
1157         GtkTooltips *tips = gtk_tooltips_new();
1158         GtkWidget *vbox;
1159         GtkWidget *hbox;
1160         gchar *text;
1161         gint index = 0;
1162
1163         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1164         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1165
1166         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1167         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1168
1169         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1170                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1171
1172         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1173         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1174         wizard->recv_type = gtk_option_menu_new();
1175         
1176         MENUITEM_ADD (menu, menuitem, _("POP3"), A_POP3);
1177         g_signal_connect(G_OBJECT(menuitem), "activate",
1178                          G_CALLBACK(wizard_protocol_changed),
1179                          wizard);
1180
1181         MENUITEM_ADD (menu, menuitem, _("IMAP"), A_IMAP4);
1182         g_signal_connect(G_OBJECT(menuitem), "activate",
1183                          G_CALLBACK(wizard_protocol_changed),
1184                          wizard);
1185
1186         MENUITEM_ADD (menu, menuitem, _("Local mbox file"), A_LOCAL);
1187         g_signal_connect(G_OBJECT(menuitem), "activate",
1188                          G_CALLBACK(wizard_protocol_changed),
1189                          wizard);
1190
1191         gtk_option_menu_set_menu (GTK_OPTION_MENU (wizard->recv_type), menu);
1192         switch(tmpl.recvtype) {
1193         case A_POP3: 
1194                 index = 0;
1195                 break;
1196         case A_IMAP4:
1197                 index = 1;
1198                 break;
1199         case A_LOCAL:
1200                 index = 2;
1201                 break;
1202         default:
1203                 index = 0;
1204         }
1205         gtk_option_menu_set_history(GTK_OPTION_MENU (wizard->recv_type), index);
1206         PACK_BOX(hbox, _("<span weight=\"bold\">Server type:</span>"),
1207                  wizard->recv_type);
1208
1209         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1210         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1211         wizard->recv_server = gtk_entry_new();
1212         text = get_default_server(wizard, "pop");
1213         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1214         g_free(text);
1215         
1216         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->recv_server,
1217                              _("You can specify the port number by appending it at the end: "
1218                                "\"mail.example.com:110\""),
1219                              NULL);
1220
1221         wizard->recv_label = gtk_label_new(_("<span weight=\"bold\">Server address:</span>"));
1222         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1223         if (GTK_IS_MISC(wizard->recv_label))                                                  
1224                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);         
1225         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_label, FALSE, FALSE, 0);
1226         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_server, TRUE, TRUE, 0);
1227         
1228         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1229         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1230         wizard->recv_username = gtk_entry_new();
1231         wizard->recv_username_label = gtk_label_new(_("<span weight=\"bold\">Username:</span>"));
1232         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_username_label), TRUE);
1233         if (GTK_IS_MISC(wizard->recv_username_label))                                                 
1234                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);        
1235         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_username_label, FALSE, FALSE, 0);
1236         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_username, TRUE, TRUE, 0);
1237         
1238         text = get_default_account(wizard);
1239         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
1240         g_free(text);
1241
1242         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1243         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1244         wizard->recv_password = gtk_entry_new();
1245         gtk_entry_set_text(GTK_ENTRY(wizard->recv_password), tmpl.recvpass?tmpl.recvpass:"");
1246         wizard->recv_password_label = gtk_label_new(_("Password:"));
1247         if (GTK_IS_MISC(wizard->recv_password_label))                                                 
1248                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);        
1249         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
1250         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_password_label, FALSE, FALSE, 0);
1251         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_password, TRUE, TRUE, 0);
1252         
1253 #ifdef USE_OPENSSL
1254         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1255         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1256         wizard->recv_use_ssl = gtk_check_button_new_with_label(
1257                                         _("Use SSL to connect to receiving server"));
1258         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl),
1259                         tmpl.recvssl != 0);
1260         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_ssl, FALSE, FALSE, 0);
1261
1262         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1263         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1264         wizard->recv_use_tls = gtk_check_button_new_with_label(
1265                                         _("Use SSL via STARTTLS"));
1266         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls),
1267                         tmpl.recvssl == 2);
1268         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_tls, FALSE, FALSE, 0);
1269         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, wizard->recv_use_tls);
1270 #endif  
1271         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1272         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1273         wizard->recv_imap_subdir = gtk_entry_new();
1274         gtk_entry_set_text(GTK_ENTRY(wizard->recv_imap_subdir), tmpl.imapdir?tmpl.imapdir:"");
1275         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
1276         if (GTK_IS_MISC(wizard->recv_imap_label))                                                     
1277                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
1278         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_label, FALSE, FALSE, 0);
1279         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_subdir, TRUE, TRUE, 0);
1280         
1281         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1282         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1283         wizard->subsonly_checkbtn = gtk_check_button_new_with_label(
1284                         _("Show only subscribed folders"));
1285         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn),
1286                         tmpl.subsonly);
1287         gtk_box_pack_start(GTK_BOX(hbox), wizard->subsonly_checkbtn, FALSE, FALSE, 0);
1288         
1289         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1290         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1291         wizard->no_imap_warning = gtk_label_new(_(
1292                           "<span weight=\"bold\">Warning: this version of Claws Mail\n"
1293                           "has been built without IMAP support.</span>"));
1294         gtk_label_set_use_markup(GTK_LABEL(wizard->no_imap_warning), TRUE);
1295         gtk_box_pack_start(GTK_BOX(hbox), wizard->no_imap_warning, FALSE, FALSE, 0);
1296
1297         return table;
1298 }
1299
1300 static void
1301 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
1302 {
1303         WizardWindow * wizard = (WizardWindow *)data;
1304         int current_page, num_pages;
1305         GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
1306         GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(menu));
1307         gint protocol = GPOINTER_TO_INT
1308                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1309         gboolean skip_mailbox_page = FALSE;
1310         
1311         if (protocol == A_IMAP4) {
1312                 skip_mailbox_page = TRUE;
1313         }
1314         
1315         num_pages = g_slist_length(wizard->pages);
1316
1317         current_page = gtk_notebook_get_current_page (
1318                                 GTK_NOTEBOOK(wizard->notebook));
1319         if (response == CANCEL)
1320         {
1321                 wizard->result = FALSE;
1322                 wizard->finished = TRUE;
1323                 gtk_widget_destroy (GTK_WIDGET(dialog));
1324         }
1325         else if (response == FINISHED)
1326         {
1327                 if (!wizard_write_config(wizard)) {
1328                         current_page = gtk_notebook_get_current_page (
1329                                         GTK_NOTEBOOK(wizard->notebook));
1330                         goto set_sens;
1331                 }
1332                 wizard->result = TRUE;
1333                 wizard->finished = TRUE;
1334                 gtk_widget_destroy (GTK_WIDGET(dialog));
1335         }
1336         else
1337         {
1338                 if (response == GO_BACK)
1339                 {
1340                         if (current_page > 0) {
1341                                 current_page--;
1342                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1343                                         /* mailbox */
1344                                         current_page--;
1345                                 }
1346                                 gtk_notebook_set_current_page (
1347                                         GTK_NOTEBOOK(wizard->notebook), 
1348                                         current_page);
1349                         }
1350                 }
1351                 else if (response == GO_FORWARD)
1352                 {
1353                         if (current_page < (num_pages-1)) {
1354                                 current_page++;
1355                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1356                                         /* mailbox */
1357                                         current_page++;
1358                                 }
1359                                 gtk_notebook_set_current_page (
1360                                         GTK_NOTEBOOK(wizard->notebook), 
1361                                         current_page);
1362                         }
1363                 }
1364 set_sens:
1365                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
1366                                 current_page > 0);
1367                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
1368                                 current_page < (num_pages - 1));
1369                 if (current_page == (num_pages -1)) {
1370                         gtk_dialog_set_response_sensitive (dialog, FINISHED, TRUE);
1371                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), FINISHED);
1372                 } else {
1373                         gtk_dialog_set_response_sensitive (dialog, FINISHED, FALSE);
1374                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), GO_FORWARD);
1375                 }
1376
1377         }
1378 }
1379
1380 static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
1381                                  gpointer data)
1382 {
1383         WizardWindow *wizard = (WizardWindow *)data;
1384         wizard->result = FALSE;
1385         wizard->finished = TRUE;
1386         
1387         return FALSE;
1388 }
1389
1390 #define PACK_WARNING(text) {                                            \
1391         label = gtk_label_new(text);                                    \
1392         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);                  \
1393         gtk_box_pack_end(GTK_BOX(widget), label, FALSE, FALSE, 0);      \
1394 }
1395
1396 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
1397         WizardWindow *wizard = g_new0(WizardWindow, 1);
1398         GtkWidget *page;
1399         GtkWidget *widget;
1400         GtkWidget *label;
1401         GtkWidget *scrolled_window;
1402         gchar     *text;
1403         GSList    *cur;
1404         gboolean   result;
1405         gint i = 0;
1406         wizard->mainwin = mainwin;
1407         wizard->create_mailbox = create_mailbox;
1408         
1409         gtk_widget_hide(mainwin->window);
1410         
1411         wizard_read_defaults();
1412         
1413         wizard->window = gtk_dialog_new_with_buttons (_("Claws Mail Setup Wizard"),
1414                         NULL, 0, 
1415                         GTK_STOCK_GO_BACK, GO_BACK,
1416                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
1417                         GTK_STOCK_SAVE, FINISHED,
1418                         GTK_STOCK_CANCEL, CANCEL,
1419                         NULL);
1420
1421         g_signal_connect(wizard->window, "response", 
1422                           G_CALLBACK(wizard_response_cb), wizard);
1423         gtk_widget_realize(wizard->window);
1424         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
1425                         GO_FORWARD);
1426         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1427                         GO_BACK, FALSE);
1428         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1429                         GO_FORWARD, TRUE);
1430         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1431                         FINISHED, FALSE);
1432         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1433                         CANCEL, TRUE);
1434         
1435         wizard->notebook = gtk_notebook_new();
1436         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
1437         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
1438         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(wizard->window)->vbox), 
1439                             wizard->notebook, TRUE, TRUE, 0);
1440         
1441         wizard->pages = NULL;
1442         
1443 /*welcome page: 0 */
1444         WELCOME_PAGE = i;
1445         page = create_page(wizard, _("Welcome to Claws Mail"));
1446         
1447         wizard->pages = g_slist_append(wizard->pages, page);
1448         widget = stock_pixmap_widget(wizard->window, 
1449                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1450
1451         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1452         
1453         text = g_strdup(_("Welcome to the Claws Mail setup wizard.\n\n"
1454                           "We will begin by defining some basic "
1455                           "information about you and your most common "
1456                           "mail options so that you can start to use "
1457                           "Claws Mail in less than five minutes."));
1458         widget = gtk_label_new(text);
1459         gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
1460         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1461         g_free(text);
1462
1463 /* user page: 1 */
1464         i++;
1465         USER_PAGE = i;
1466         widget = create_page (wizard, _("About You"));
1467         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1468         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1469                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1470         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1471
1472         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1473                                               user_page(wizard));
1474         PACK_WARNING(_("Bold fields must be completed"));
1475         
1476         wizard->pages = g_slist_append(wizard->pages, widget);
1477
1478 /* recv+auth page: 2 */
1479         i++;
1480         RECV_PAGE = i;
1481         widget = create_page (wizard, _("Receiving mail"));
1482         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1483         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1484                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1485         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1486
1487         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1488                                               recv_page(wizard));
1489         PACK_WARNING(_("Bold fields must be completed"));
1490         
1491         wizard->pages = g_slist_append(wizard->pages, widget);
1492
1493 /*smtp page: 3 */
1494         i++;
1495         SMTP_PAGE = i;
1496         widget = create_page (wizard, _("Sending mail"));
1497         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1498         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1499                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1500         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1501
1502         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1503                                               smtp_page(wizard));
1504         PACK_WARNING(_("Bold fields must be completed"));
1505         
1506         wizard->pages = g_slist_append(wizard->pages, widget);
1507
1508 /* mailbox page: 4 */
1509         if (create_mailbox) {
1510                 i++;
1511                 MAILBOX_PAGE = i;
1512                 widget = create_page (wizard, _("Saving mail on disk"));
1513                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1514                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1515                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1516                 gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1517
1518                 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1519                                               mailbox_page(wizard));
1520                 PACK_WARNING(_("Bold fields must be completed"));
1521         
1522                 wizard->pages = g_slist_append(wizard->pages, widget);
1523         }
1524
1525 /* done page: 6 */
1526         i++;
1527         DONE_PAGE = i;
1528         page = create_page(wizard, _("Configuration finished"));
1529         
1530         wizard->pages = g_slist_append(wizard->pages, page);
1531         widget = stock_pixmap_widget(wizard->window, 
1532                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1533
1534         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1535         
1536         text = g_strdup(_("Claws Mail is now ready.\n"
1537                           "Click Save to start."));
1538         widget = gtk_label_new(text);
1539         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1540         g_free(text);
1541
1542
1543         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
1544                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
1545                                           GTK_WIDGET(cur->data), NULL);
1546         }
1547         
1548         g_signal_connect(G_OBJECT(wizard->window), "delete_event",
1549                          G_CALLBACK(wizard_close_cb), wizard);
1550         gtk_widget_show_all (wizard->window);
1551
1552         gtk_widget_hide(wizard->recv_imap_label);
1553         gtk_widget_hide(wizard->recv_imap_subdir);
1554         gtk_widget_hide(wizard->subsonly_checkbtn);
1555
1556         wizard_protocol_change(wizard, tmpl.recvtype);
1557
1558         while (!wizard->finished)
1559                 gtk_main_iteration();
1560
1561         result = wizard->result;
1562         
1563         GTK_EVENTS_FLUSH();
1564
1565         gtk_widget_show(mainwin->window);
1566         g_free(wizard);
1567
1568         return result;
1569 }