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