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