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