07bdd1aa2471b36b812c32cffc3c6ba0f3a7a91b
[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                         (!strcmp("Mail", gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name))))
692                                 ?_("Mailbox"):tmp);
693         g_free(tmp);
694         prefs_account->local_inbox = g_strdup(prefs_account->inbox);
695
696         if (prefs_account->protocol != A_LOCAL)
697                 prefs_account->recv_server = g_strdup(recv_server);
698         else
699                 prefs_account->local_mbox = g_strdup(recv_server);
700
701         g_free(recv_server);
702         g_free(smtp_server);
703
704         prefs_account->userid = g_strdup(
705                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
706         prefs_account->passwd = g_strdup(
707                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)));
708
709         prefs_account->smtp_userid = g_strdup(
710                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)));
711         prefs_account->smtp_passwd = g_strdup(
712                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_password)));
713         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
714                 prefs_account->use_smtp_auth = TRUE;
715         }
716
717 #ifdef USE_OPENSSL
718         smtp_ssl_type = SSL_NONE;
719         recv_ssl_type = SSL_NONE;       
720
721         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl))) {
722                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls)))
723                         smtp_ssl_type = SSL_STARTTLS;
724                 else
725                         smtp_ssl_type = SSL_TUNNEL;
726         }
727         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
728                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls)))
729                         recv_ssl_type = SSL_STARTTLS;
730                 else
731                         recv_ssl_type = SSL_TUNNEL;
732         }
733
734         prefs_account->ssl_smtp = smtp_ssl_type;
735
736         if (prefs_account->protocol == A_IMAP4)
737                 prefs_account->ssl_imap = recv_ssl_type;
738         else
739                 prefs_account->ssl_pop = recv_ssl_type;
740
741 #endif
742         if (prefs_account->protocol == A_IMAP4) {
743                 gchar *directory = gtk_editable_get_chars(
744                         GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
745                 if (directory && strlen(directory)) {
746                         prefs_account->imap_dir = g_strdup(directory);
747                 }
748                 prefs_account->imap_subsonly = 
749                         gtk_toggle_button_get_active(
750                                 GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn));
751                 g_free(directory);
752         }
753
754         account_list = g_list_append(account_list, prefs_account);
755         prefs_account_write_config_all(account_list);
756         prefs_account_free(prefs_account);
757         account_read_config_all();
758
759         initialize_fonts(wizard);
760         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4)
761                 write_welcome_email(wizard);
762         
763 #ifndef G_OS_WIN32 
764         plugin_load_standard_plugins();
765 #endif
766         return TRUE;
767 }
768
769 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
770 {
771         GtkWidget *w;
772         GtkWidget *vbox;
773         GtkWidget *hbox;
774         GtkWidget *image;
775         char *title_string;
776
777         vbox = gtk_vbox_new (FALSE, 6);
778         gtk_container_set_border_width  (GTK_CONTAINER(vbox), 10);
779
780         /* create the titlebar */
781         hbox = gtk_hbox_new (FALSE, 12);
782         image = stock_pixmap_widget(wizard->window, 
783                                 STOCK_PIXMAP_CLAWS_MAIL_ICON);
784         gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
785         title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
786         w = gtk_label_new (title_string);
787         gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
788         g_free (title_string);
789         gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
790
791         /* pack the titlebar */
792         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
793
794         /* pack the separator */
795         gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
796
797         /* pack space */
798         w = gtk_alignment_new (0, 0, 0, 0);
799         gtk_widget_set_size_request (w, 0, 6);
800         gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
801
802         return vbox;
803 }
804
805 #define PACK_BOX(hbox,text,entry) {                                     \
806         GtkWidget *label = gtk_label_new(text);                         \
807         gtk_label_set_use_markup(GTK_LABEL(label), TRUE);               \
808         if (GTK_IS_MISC(label))                                         \
809                 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);        \
810         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);      \
811         gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);        \
812 }
813
814 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
815 {
816         if (!strcmp(type, "smtp")) {
817                 if (!tmpl.smtpserver || !strlen(tmpl.smtpserver))
818                         return g_strconcat(type, ".", tmpl.domain, NULL);
819                 else 
820                         return g_strdup(tmpl.smtpserver);
821         } else {
822                 if (!tmpl.recvserver || !strlen(tmpl.recvserver))
823                         return g_strconcat(type, ".", tmpl.domain, NULL);
824                 else 
825                         return g_strdup(tmpl.recvserver);
826         }
827 }
828
829 static gchar *get_default_account(WizardWindow * wizard)
830 {
831         gchar *result = NULL;
832         
833         if (!tmpl.recvuser || !strlen(tmpl.recvuser)) {
834                 result = gtk_editable_get_chars(
835                                 GTK_EDITABLE(wizard->email), 0, -1);
836
837                 if (strstr(result, "@")) {
838                         *(strstr(result,"@")) = '\0';
839                 } 
840         } else {
841                 result = g_strdup(tmpl.recvuser);
842         }
843         return result;
844 }
845
846 static gchar *get_default_smtp_account(WizardWindow * wizard)
847 {
848         gchar *result = NULL;
849         
850         if (!tmpl.smtpuser || !strlen(tmpl.smtpuser)) {
851                 return g_strdup("");
852         } else {
853                 result = g_strdup(tmpl.smtpuser);
854         }
855         return result;
856 }
857
858 static void wizard_email_changed(GtkWidget *widget, gpointer data)
859 {
860         WizardWindow *wizard = (WizardWindow *)data;
861         RecvProtocol protocol;
862         gchar *text;
863         protocol = GPOINTER_TO_INT
864                 (g_object_get_data(G_OBJECT(wizard->recv_type), MENU_VAL_ID));
865         
866         text = get_default_server(wizard, "smtp");
867         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
868         g_free(text);
869
870         text = get_default_account(wizard);
871         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
872         g_free(text);
873
874         if (protocol == A_POP3) {
875                 text = get_default_server(wizard, "pop");
876                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
877                 g_free(text);
878         } else if (protocol == A_IMAP4) {
879                 text = get_default_server(wizard, "imap");
880                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
881                 g_free(text);
882         } else if (protocol == A_LOCAL) {
883                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
884         }
885         
886 }
887
888 static GtkWidget* user_page (WizardWindow * wizard)
889 {
890         GtkWidget *table = gtk_table_new(1,1, FALSE);
891         GtkWidget *vbox;
892         GtkWidget *hbox;
893         
894         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
895         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
896
897         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
898         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
899
900         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
901                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
902
903         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
904         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
905         wizard->full_name = gtk_entry_new();
906         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), tmpl.name?tmpl.name:"");
907         PACK_BOX(hbox, _("<span weight=\"bold\">Your name:</span>"),
908                  wizard->full_name);
909         
910         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
911         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
912         wizard->email = gtk_entry_new();
913         gtk_entry_set_text(GTK_ENTRY(wizard->email), tmpl.email?tmpl.email:"");
914         PACK_BOX(hbox, _("<span weight=\"bold\">Your email address:</span>"),
915                  wizard->email);
916         
917         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
918         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);      
919         wizard->organization = gtk_entry_new();
920         gtk_entry_set_text(GTK_ENTRY(wizard->organization), tmpl.organization?tmpl.organization:"");
921         PACK_BOX(hbox, _("Your organization:"), wizard->organization);
922         
923         g_signal_connect(G_OBJECT(wizard->email), "changed",
924                          G_CALLBACK(wizard_email_changed),
925                          wizard);
926         return table;
927 }
928
929 static GtkWidget* mailbox_page (WizardWindow * wizard)
930 {
931         GtkWidget *table = gtk_table_new(1,1, FALSE);
932         GtkWidget *vbox;
933         GtkWidget *hbox;
934         GtkTooltips *tips = gtk_tooltips_new();
935
936         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
937         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
938
939         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
940         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
941
942         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
943                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
944
945         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
946         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
947         wizard->mailbox_name = gtk_entry_new();
948         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), tmpl.mailbox?tmpl.mailbox:"");
949
950         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->mailbox_name,
951                              _("You can also specify an absolute path, for example: "
952                                "\"/home/john/Documents/Mail\""),
953                              NULL);
954
955         PACK_BOX(hbox, _("<span weight=\"bold\">Mailbox name:</span>"),
956                  wizard->mailbox_name);
957         
958         return table;
959 }
960
961 static void smtp_auth_changed (GtkWidget *btn, gpointer data)
962 {
963         WizardWindow *wizard = (WizardWindow *)data;
964         gboolean do_auth = gtk_toggle_button_get_active(
965                 GTK_TOGGLE_BUTTON(wizard->smtp_auth));
966         gtk_widget_set_sensitive(wizard->smtp_username, do_auth);
967         gtk_widget_set_sensitive(wizard->smtp_username_label, do_auth);
968         gtk_widget_set_sensitive(wizard->smtp_password, do_auth);
969         gtk_widget_set_sensitive(wizard->smtp_password_label, do_auth);
970 }
971
972 static GtkWidget* smtp_page (WizardWindow * wizard)
973 {
974         GtkWidget *table = gtk_table_new(1, 1, FALSE);
975         GtkWidget *vbox;
976         GtkWidget *hbox;
977         GtkTooltips *tips = gtk_tooltips_new();
978         gchar *text;
979         
980         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
981         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
982
983         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
984         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
985
986         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
987                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
988
989         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
990         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
991         wizard->smtp_server = gtk_entry_new();
992         text = get_default_server(wizard, "smtp");
993         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
994         g_free(text);
995
996         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->smtp_server,
997                              _("You can specify the port number by appending it at the end: "
998                                "\"mail.example.com:25\""),
999                              NULL);
1000
1001         PACK_BOX(hbox, _("<span weight=\"bold\">SMTP server address:</span>"),
1002                  wizard->smtp_server);
1003
1004
1005         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1006         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1007         wizard->smtp_auth = gtk_check_button_new_with_label(
1008                                         _("Use authentication"));
1009         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth),
1010                         tmpl.smtpauth);
1011         g_signal_connect(G_OBJECT(wizard->smtp_auth), "toggled",
1012                          G_CALLBACK(smtp_auth_changed),
1013                          wizard);
1014         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_auth, FALSE, FALSE, 0);
1015
1016         text = get_default_smtp_account(wizard);
1017
1018         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1019         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1020         wizard->smtp_username = gtk_entry_new();
1021         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_username), text);
1022         g_free(text);
1023         wizard->smtp_username_label = gtk_label_new(_("SMTP username:\n"
1024                                         "<span size=\"small\">(empty to use the same as receive)</span>"));
1025         gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_username_label), TRUE);
1026         if (GTK_IS_MISC(wizard->smtp_username_label))                                                 
1027                 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_username_label), 1, 0.5);        
1028         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_username_label, FALSE, FALSE, 0);
1029         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_username, TRUE, TRUE, 0);
1030
1031         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1032         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1033         wizard->smtp_password = gtk_entry_new();
1034         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_password), tmpl.smtppass?tmpl.smtppass:""); 
1035         gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_password), FALSE);
1036         wizard->smtp_password_label = gtk_label_new(_("SMTP password:\n"
1037                                         "<span size=\"small\">(empty to use the same as receive)</span>"));
1038         gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_password_label), TRUE);
1039         if (GTK_IS_MISC(wizard->smtp_password_label))                                                 
1040                 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_password_label), 1, 0.5);        
1041         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_password_label, FALSE, FALSE, 0);
1042         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_password, TRUE, TRUE, 0);
1043 #ifdef USE_OPENSSL
1044         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1045         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1046         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
1047                                         _("Use SSL to connect to SMTP server"));
1048         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl),
1049                         tmpl.smtpssl != 0);
1050         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_ssl, FALSE, FALSE, 0);
1051
1052         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1053         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1054         wizard->smtp_use_tls = gtk_check_button_new_with_label(
1055                                         _("Use SSL via STARTTLS"));
1056         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_tls),
1057                         tmpl.smtpssl == 2);
1058         gtk_box_pack_start(GTK_BOX(hbox), wizard->smtp_use_tls, FALSE, FALSE, 0);
1059         SET_TOGGLE_SENSITIVITY (wizard->smtp_use_ssl, wizard->smtp_use_tls);
1060 #endif
1061         smtp_auth_changed(NULL, wizard);
1062         return table;
1063 }
1064
1065 static void wizard_protocol_change(WizardWindow *wizard, RecvProtocol protocol)
1066 {
1067         gchar *text;
1068         
1069         if (protocol == A_POP3) {
1070                 text = get_default_server(wizard, "pop");
1071                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1072                 gtk_widget_hide(wizard->recv_imap_label);
1073                 gtk_widget_hide(wizard->recv_imap_subdir);
1074                 gtk_widget_hide(wizard->subsonly_checkbtn);
1075                 gtk_widget_show(wizard->recv_username);
1076                 gtk_widget_show(wizard->recv_password);
1077                 gtk_widget_show(wizard->recv_username_label);
1078                 gtk_widget_show(wizard->recv_password_label);
1079                 gtk_widget_hide(wizard->no_imap_warning);
1080 #ifdef USE_OPENSSL
1081                 gtk_widget_show(wizard->recv_use_ssl);
1082                 gtk_widget_show(wizard->recv_use_tls);
1083 #endif
1084                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1085                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1086                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1087                 g_free(text);
1088         } else if (protocol == A_IMAP4) {
1089 #ifdef HAVE_LIBETPAN
1090                 text = get_default_server(wizard, "imap");
1091                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1092                 gtk_widget_show(wizard->recv_imap_label);
1093                 gtk_widget_show(wizard->recv_imap_subdir);
1094                 gtk_widget_show(wizard->subsonly_checkbtn);
1095                 gtk_widget_show(wizard->recv_username);
1096                 gtk_widget_show(wizard->recv_password);
1097                 gtk_widget_show(wizard->recv_username_label);
1098                 gtk_widget_show(wizard->recv_password_label);
1099                 gtk_widget_hide(wizard->no_imap_warning);
1100 #ifdef USE_OPENSSL
1101                 gtk_widget_show(wizard->recv_use_ssl);
1102                 gtk_widget_show(wizard->recv_use_tls);
1103 #endif
1104                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
1105                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1106                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1107                 g_free(text);
1108 #else
1109                 gtk_widget_hide(wizard->recv_imap_label);
1110                 gtk_widget_hide(wizard->recv_imap_subdir);
1111                 gtk_widget_hide(wizard->subsonly_checkbtn);
1112                 gtk_widget_hide(wizard->recv_username);
1113                 gtk_widget_hide(wizard->recv_password);
1114                 gtk_widget_hide(wizard->recv_username_label);
1115                 gtk_widget_hide(wizard->recv_password_label);
1116                 gtk_widget_show(wizard->no_imap_warning);
1117 #ifdef USE_OPENSSL
1118                 gtk_widget_hide(wizard->recv_use_ssl);
1119                 gtk_widget_hide(wizard->recv_use_tls);
1120 #endif
1121                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, FALSE);
1122 #endif
1123         } else if (protocol == A_LOCAL) {
1124                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
1125                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Local mailbox:</span>"));
1126                 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1127                 gtk_widget_hide(wizard->no_imap_warning);
1128                 gtk_widget_hide(wizard->recv_imap_label);
1129                 gtk_widget_hide(wizard->recv_imap_subdir);
1130                 gtk_widget_hide(wizard->subsonly_checkbtn);
1131                 gtk_widget_hide(wizard->recv_username);
1132                 gtk_widget_hide(wizard->recv_password);
1133                 gtk_widget_hide(wizard->recv_username_label);
1134                 gtk_widget_hide(wizard->recv_password_label);
1135 #ifdef USE_OPENSSL
1136                 gtk_widget_hide(wizard->recv_use_ssl);
1137                 gtk_widget_hide(wizard->recv_use_tls);
1138 #endif
1139                 gtk_dialog_set_response_sensitive (GTK_DIALOG(wizard->window), GO_FORWARD, TRUE);
1140         }
1141 }
1142
1143 static void wizard_protocol_changed(GtkMenuItem *menuitem, gpointer data)
1144 {
1145         WizardWindow *wizard = (WizardWindow *)data;
1146         RecvProtocol protocol;
1147         protocol = GPOINTER_TO_INT
1148                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1149
1150         wizard_protocol_change(wizard, protocol);       
1151 }
1152
1153 static GtkWidget* recv_page (WizardWindow * wizard)
1154 {
1155         GtkWidget *table = gtk_table_new(1,1, FALSE);
1156         GtkWidget *menu = gtk_menu_new();
1157         GtkWidget *menuitem;
1158         GtkTooltips *tips = gtk_tooltips_new();
1159         GtkWidget *vbox;
1160         GtkWidget *hbox;
1161         gchar *text;
1162         gint index = 0;
1163
1164         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1165         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1166
1167         vbox = gtk_vbox_new(FALSE, VSPACING_NARROW);
1168         gtk_container_set_border_width(GTK_CONTAINER(vbox), VSPACING_NARROW_2);
1169
1170         gtk_table_attach(GTK_TABLE(table), vbox, 0,1,1,2, 
1171                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
1172
1173         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1174         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1175         wizard->recv_type = gtk_option_menu_new();
1176         
1177         MENUITEM_ADD (menu, menuitem, _("POP3"), A_POP3);
1178         g_signal_connect(G_OBJECT(menuitem), "activate",
1179                          G_CALLBACK(wizard_protocol_changed),
1180                          wizard);
1181
1182         MENUITEM_ADD (menu, menuitem, _("IMAP"), A_IMAP4);
1183         g_signal_connect(G_OBJECT(menuitem), "activate",
1184                          G_CALLBACK(wizard_protocol_changed),
1185                          wizard);
1186
1187         MENUITEM_ADD (menu, menuitem, _("Local mbox file"), A_LOCAL);
1188         g_signal_connect(G_OBJECT(menuitem), "activate",
1189                          G_CALLBACK(wizard_protocol_changed),
1190                          wizard);
1191
1192         gtk_option_menu_set_menu (GTK_OPTION_MENU (wizard->recv_type), menu);
1193         switch(tmpl.recvtype) {
1194         case A_POP3: 
1195                 index = 0;
1196                 break;
1197         case A_IMAP4:
1198                 index = 1;
1199                 break;
1200         case A_LOCAL:
1201                 index = 2;
1202                 break;
1203         default:
1204                 index = 0;
1205         }
1206         gtk_option_menu_set_history(GTK_OPTION_MENU (wizard->recv_type), index);
1207         PACK_BOX(hbox, _("<span weight=\"bold\">Server type:</span>"),
1208                  wizard->recv_type);
1209
1210         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1211         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1212         wizard->recv_server = gtk_entry_new();
1213         text = get_default_server(wizard, "pop");
1214         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1215         g_free(text);
1216         
1217         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), wizard->recv_server,
1218                              _("You can specify the port number by appending it at the end: "
1219                                "\"mail.example.com:110\""),
1220                              NULL);
1221
1222         wizard->recv_label = gtk_label_new(_("<span weight=\"bold\">Server address:</span>"));
1223         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1224         if (GTK_IS_MISC(wizard->recv_label))                                                  
1225                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);         
1226         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_label, FALSE, FALSE, 0);
1227         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_server, TRUE, TRUE, 0);
1228         
1229         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1230         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1231         wizard->recv_username = gtk_entry_new();
1232         wizard->recv_username_label = gtk_label_new(_("<span weight=\"bold\">Username:</span>"));
1233         gtk_label_set_use_markup(GTK_LABEL(wizard->recv_username_label), TRUE);
1234         if (GTK_IS_MISC(wizard->recv_username_label))                                                 
1235                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);        
1236         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_username_label, FALSE, FALSE, 0);
1237         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_username, TRUE, TRUE, 0);
1238         
1239         text = get_default_account(wizard);
1240         gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
1241         g_free(text);
1242
1243         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1244         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1245         wizard->recv_password = gtk_entry_new();
1246         gtk_entry_set_text(GTK_ENTRY(wizard->recv_password), tmpl.recvpass?tmpl.recvpass:"");
1247         wizard->recv_password_label = gtk_label_new(_("Password:"));
1248         if (GTK_IS_MISC(wizard->recv_password_label))                                                 
1249                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);        
1250         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
1251         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_password_label, FALSE, FALSE, 0);
1252         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_password, TRUE, TRUE, 0);
1253         
1254 #ifdef USE_OPENSSL
1255         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1256         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1257         wizard->recv_use_ssl = gtk_check_button_new_with_label(
1258                                         _("Use SSL to connect to receiving server"));
1259         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl),
1260                         tmpl.recvssl != 0);
1261         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_ssl, FALSE, FALSE, 0);
1262
1263         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1264         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1265         wizard->recv_use_tls = gtk_check_button_new_with_label(
1266                                         _("Use SSL via STARTTLS"));
1267         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_tls),
1268                         tmpl.recvssl == 2);
1269         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_use_tls, FALSE, FALSE, 0);
1270         SET_TOGGLE_SENSITIVITY (wizard->recv_use_ssl, wizard->recv_use_tls);
1271 #endif  
1272         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1273         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1274         wizard->recv_imap_subdir = gtk_entry_new();
1275         gtk_entry_set_text(GTK_ENTRY(wizard->recv_imap_subdir), tmpl.imapdir?tmpl.imapdir:"");
1276         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
1277         if (GTK_IS_MISC(wizard->recv_imap_label))                                                     
1278                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
1279         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_label, FALSE, FALSE, 0);
1280         gtk_box_pack_start(GTK_BOX(hbox), wizard->recv_imap_subdir, TRUE, TRUE, 0);
1281         
1282         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1283         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1284         wizard->subsonly_checkbtn = gtk_check_button_new_with_label(
1285                         _("Show only subscribed folders"));
1286         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->subsonly_checkbtn),
1287                         tmpl.subsonly);
1288         gtk_box_pack_start(GTK_BOX(hbox), wizard->subsonly_checkbtn, FALSE, FALSE, 0);
1289         
1290         hbox = gtk_hbox_new(FALSE, VSPACING_NARROW);
1291         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1292         wizard->no_imap_warning = gtk_label_new(_(
1293                           "<span weight=\"bold\">Warning: this version of Claws Mail\n"
1294                           "has been built without IMAP support.</span>"));
1295         gtk_label_set_use_markup(GTK_LABEL(wizard->no_imap_warning), TRUE);
1296         gtk_box_pack_start(GTK_BOX(hbox), wizard->no_imap_warning, FALSE, FALSE, 0);
1297
1298         return table;
1299 }
1300
1301 static void
1302 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
1303 {
1304         WizardWindow * wizard = (WizardWindow *)data;
1305         int current_page, num_pages;
1306         GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
1307         GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(menu));
1308         gint protocol = GPOINTER_TO_INT
1309                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1310         gboolean skip_mailbox_page = FALSE;
1311         
1312         if (protocol == A_IMAP4) {
1313                 skip_mailbox_page = TRUE;
1314         }
1315         
1316         num_pages = g_slist_length(wizard->pages);
1317
1318         current_page = gtk_notebook_get_current_page (
1319                                 GTK_NOTEBOOK(wizard->notebook));
1320         if (response == CANCEL)
1321         {
1322                 wizard->result = FALSE;
1323                 wizard->finished = TRUE;
1324                 gtk_widget_destroy (GTK_WIDGET(dialog));
1325         }
1326         else if (response == FINISHED)
1327         {
1328                 if (!wizard_write_config(wizard)) {
1329                         current_page = gtk_notebook_get_current_page (
1330                                         GTK_NOTEBOOK(wizard->notebook));
1331                         goto set_sens;
1332                 }
1333                 wizard->result = TRUE;
1334                 wizard->finished = TRUE;
1335                 gtk_widget_destroy (GTK_WIDGET(dialog));
1336         }
1337         else
1338         {
1339                 if (response == GO_BACK)
1340                 {
1341                         if (current_page > 0) {
1342                                 current_page--;
1343                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1344                                         /* mailbox */
1345                                         current_page--;
1346                                 }
1347                                 gtk_notebook_set_current_page (
1348                                         GTK_NOTEBOOK(wizard->notebook), 
1349                                         current_page);
1350                         }
1351                 }
1352                 else if (response == GO_FORWARD)
1353                 {
1354                         if (current_page < (num_pages-1)) {
1355                                 current_page++;
1356                                 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1357                                         /* mailbox */
1358                                         current_page++;
1359                                 }
1360                                 gtk_notebook_set_current_page (
1361                                         GTK_NOTEBOOK(wizard->notebook), 
1362                                         current_page);
1363                         }
1364                 }
1365 set_sens:
1366                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
1367                                 current_page > 0);
1368                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
1369                                 current_page < (num_pages - 1));
1370                 if (current_page == (num_pages -1)) {
1371                         gtk_dialog_set_response_sensitive (dialog, FINISHED, TRUE);
1372                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), FINISHED);
1373                 } else {
1374                         gtk_dialog_set_response_sensitive (dialog, FINISHED, FALSE);
1375                         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), GO_FORWARD);
1376                 }
1377
1378         }
1379 }
1380
1381 static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
1382                                  gpointer data)
1383 {
1384         WizardWindow *wizard = (WizardWindow *)data;
1385         wizard->result = FALSE;
1386         wizard->finished = TRUE;
1387         
1388         return FALSE;
1389 }
1390
1391 #define PACK_WARNING(text) {                                            \
1392         label = gtk_label_new(text);                                    \
1393         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);                  \
1394         gtk_box_pack_end(GTK_BOX(widget), label, FALSE, FALSE, 0);      \
1395 }
1396
1397 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
1398         WizardWindow *wizard = g_new0(WizardWindow, 1);
1399         GtkWidget *page;
1400         GtkWidget *widget;
1401         GtkWidget *label;
1402         GtkWidget *scrolled_window;
1403         gchar     *text;
1404         GSList    *cur;
1405         gboolean   result;
1406         gint i = 0;
1407         wizard->mainwin = mainwin;
1408         wizard->create_mailbox = create_mailbox;
1409         
1410         gtk_widget_hide(mainwin->window);
1411         
1412         wizard_read_defaults();
1413         
1414         wizard->window = gtk_dialog_new_with_buttons (_("Claws Mail Setup Wizard"),
1415                         NULL, 0, 
1416                         GTK_STOCK_GO_BACK, GO_BACK,
1417                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
1418                         GTK_STOCK_SAVE, FINISHED,
1419                         GTK_STOCK_CANCEL, CANCEL,
1420                         NULL);
1421
1422         g_signal_connect(wizard->window, "response", 
1423                           G_CALLBACK(wizard_response_cb), wizard);
1424         gtk_widget_realize(wizard->window);
1425         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
1426                         GO_FORWARD);
1427         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1428                         GO_BACK, FALSE);
1429         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1430                         GO_FORWARD, TRUE);
1431         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1432                         FINISHED, FALSE);
1433         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
1434                         CANCEL, TRUE);
1435         
1436         wizard->notebook = gtk_notebook_new();
1437         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
1438         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
1439         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(wizard->window)->vbox), 
1440                             wizard->notebook, TRUE, TRUE, 0);
1441         
1442         wizard->pages = NULL;
1443         
1444 /*welcome page: 0 */
1445         WELCOME_PAGE = i;
1446         page = create_page(wizard, _("Welcome to Claws Mail"));
1447         
1448         wizard->pages = g_slist_append(wizard->pages, page);
1449         widget = stock_pixmap_widget(wizard->window, 
1450                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1451
1452         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1453         
1454         text = g_strdup(_("Welcome to the Claws Mail setup wizard.\n\n"
1455                           "We will begin by defining some basic "
1456                           "information about you and your most common "
1457                           "mail options so that you can start to use "
1458                           "Claws Mail in less than five minutes."));
1459         widget = gtk_label_new(text);
1460         gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
1461         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1462         g_free(text);
1463
1464 /* user page: 1 */
1465         i++;
1466         USER_PAGE = i;
1467         widget = create_page (wizard, _("About You"));
1468         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1469         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1470                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1471         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1472
1473         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1474                                               user_page(wizard));
1475         PACK_WARNING(_("Bold fields must be completed"));
1476         
1477         wizard->pages = g_slist_append(wizard->pages, widget);
1478
1479 /* recv+auth page: 2 */
1480         i++;
1481         RECV_PAGE = i;
1482         widget = create_page (wizard, _("Receiving mail"));
1483         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1484         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1485                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1486         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1487
1488         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1489                                               recv_page(wizard));
1490         PACK_WARNING(_("Bold fields must be completed"));
1491         
1492         wizard->pages = g_slist_append(wizard->pages, widget);
1493
1494 /*smtp page: 3 */
1495         i++;
1496         SMTP_PAGE = i;
1497         widget = create_page (wizard, _("Sending mail"));
1498         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1499         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1500                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1501         gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1502
1503         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1504                                               smtp_page(wizard));
1505         PACK_WARNING(_("Bold fields must be completed"));
1506         
1507         wizard->pages = g_slist_append(wizard->pages, widget);
1508
1509 /* mailbox page: 4 */
1510         if (create_mailbox) {
1511                 i++;
1512                 MAILBOX_PAGE = i;
1513                 widget = create_page (wizard, _("Saving mail on disk"));
1514                 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1515                 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1516                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1517                 gtk_box_pack_start(GTK_BOX(widget), scrolled_window, TRUE, TRUE, 0);
1518
1519                 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
1520                                               mailbox_page(wizard));
1521                 PACK_WARNING(_("Bold fields must be completed"));
1522         
1523                 wizard->pages = g_slist_append(wizard->pages, widget);
1524         }
1525
1526 /* done page: 6 */
1527         i++;
1528         DONE_PAGE = i;
1529         page = create_page(wizard, _("Configuration finished"));
1530         
1531         wizard->pages = g_slist_append(wizard->pages, page);
1532         widget = stock_pixmap_widget(wizard->window, 
1533                                 STOCK_PIXMAP_CLAWS_MAIL_LOGO);
1534
1535         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1536         
1537         text = g_strdup(_("Claws Mail is now ready.\n"
1538                           "Click Save to start."));
1539         widget = gtk_label_new(text);
1540         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1541         g_free(text);
1542
1543
1544         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
1545                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
1546                                           GTK_WIDGET(cur->data), NULL);
1547         }
1548         
1549         g_signal_connect(G_OBJECT(wizard->window), "delete_event",
1550                          G_CALLBACK(wizard_close_cb), wizard);
1551         gtk_widget_show_all (wizard->window);
1552
1553         gtk_widget_hide(wizard->recv_imap_label);
1554         gtk_widget_hide(wizard->recv_imap_subdir);
1555         gtk_widget_hide(wizard->subsonly_checkbtn);
1556
1557         wizard_protocol_change(wizard, tmpl.recvtype);
1558
1559         while (!wizard->finished)
1560                 gtk_main_iteration();
1561
1562         result = wizard->result;
1563         
1564         GTK_EVENTS_FLUSH();
1565
1566         gtk_widget_show(mainwin->window);
1567         g_free(wizard);
1568
1569         return result;
1570 }