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