2011-09-18 [colin] 3.7.10cvs17
[claws.git] / src / news.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #ifdef HAVE_LIBETPAN
25
26 #include "defs.h"
27
28 #include <glib.h>
29 #include <glib/gi18n.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <dirent.h>
34 #include <unistd.h>
35 #include <time.h>
36 #include <libetpan/libetpan.h>
37
38 #include "nntp-thread.h"
39 #include "news.h"
40 #include "news_gtk.h"
41 #include "socket.h"
42 #include "recv.h"
43 #include "procmsg.h"
44 #include "procheader.h"
45 #include "folder.h"
46 #include "session.h"
47 #include "statusbar.h"
48 #include "codeconv.h"
49 #include "utils.h"
50 #include "prefs_common.h"
51 #include "prefs_account.h"
52 #include "inputdialog.h"
53 #include "log.h"
54 #include "progressindicator.h"
55 #include "remotefolder.h"
56 #include "alertpanel.h"
57 #include "inc.h"
58 #ifdef USE_GNUTLS
59 #  include "ssl.h"
60 #endif
61
62 #define NNTP_PORT       119
63 #ifdef USE_GNUTLS
64 #define NNTPS_PORT      563
65 #endif
66
67 typedef struct _NewsFolder      NewsFolder;
68 typedef struct _NewsSession     NewsSession;
69
70 #define NEWS_FOLDER(obj)        ((NewsFolder *)obj)
71 #define NEWS_SESSION(obj)       ((NewsSession *)obj)
72
73 struct _NewsFolder
74 {
75         RemoteFolder rfolder;
76
77         gboolean use_auth;
78         gboolean lock_count;
79         guint refcnt;
80 };
81
82 struct _NewsSession
83 {
84         Session session;
85
86         gchar *group;
87 };
88
89 static void news_folder_init(Folder *folder, const gchar *name,
90                              const gchar *path);
91
92 static Folder   *news_folder_new        (const gchar    *name,
93                                          const gchar    *folder);
94 static void      news_folder_destroy    (Folder         *folder);
95
96 static gchar *news_fetch_msg            (Folder         *folder,
97                                          FolderItem     *item,
98                                          gint            num);
99 static void news_remove_cached_msg      (Folder         *folder, 
100                                          FolderItem     *item, 
101                                          MsgInfo        *msginfo);
102 #ifdef USE_GNUTLS
103 static Session *news_session_new         (Folder        *folder,
104                                           const gchar   *server,
105                                           gushort        port,
106                                           const gchar   *userid,
107                                           const gchar   *passwd,
108                                           SSLType        ssl_type);
109 #else
110 static Session *news_session_new         (Folder        *folder,
111                                           const gchar   *server,
112                                           gushort        port,
113                                           const gchar   *userid,
114                                           const gchar   *passwd);
115 #endif
116
117 static gint news_get_article             (Folder        *folder,
118                                           gint           num,
119                                           gchar         *filename);
120
121 static gint news_select_group            (Folder        *folder,
122                                           const gchar   *group,
123                                           gint          *num,
124                                           gint          *first,
125                                           gint          *last);
126 static MsgInfo *news_parse_xover         (struct newsnntp_xover_resp_item *item);
127 static gint news_get_num_list                    (Folder        *folder, 
128                                           FolderItem    *item,
129                                           GSList       **list,
130                                           gboolean      *old_uids_valid);
131 static MsgInfo *news_get_msginfo                 (Folder        *folder, 
132                                           FolderItem    *item,
133                                           gint           num);
134 static GSList *news_get_msginfos                 (Folder        *folder,
135                                           FolderItem    *item,
136                                           GSList        *msgnum_list);
137 static gboolean news_scan_required               (Folder        *folder,
138                                           FolderItem    *item);
139
140 static gchar *news_folder_get_path       (Folder        *folder);
141 static gchar *news_item_get_path                 (Folder        *folder,
142                                           FolderItem    *item);
143 static void news_synchronise             (FolderItem    *item, gint days);
144 static int news_remove_msg               (Folder        *folder, 
145                                           FolderItem    *item, 
146                                           gint           msgnum);
147 static gint news_rename_folder           (Folder *folder,
148                                           FolderItem *item,
149                                           const gchar *name);
150 static gint news_remove_folder           (Folder        *folder,
151                                           FolderItem    *item);
152 static FolderClass news_class;
153
154 FolderClass *news_get_class(void)
155 {
156         if (news_class.idstr == NULL) {
157                 news_class.type = F_NEWS;
158                 news_class.idstr = "news";
159                 news_class.uistr = "News";
160
161                 /* Folder functions */
162                 news_class.new_folder = news_folder_new;
163                 news_class.destroy_folder = news_folder_destroy;
164
165                 /* FolderItem functions */
166                 news_class.item_get_path = news_item_get_path;
167                 news_class.get_num_list = news_get_num_list;
168                 news_class.scan_required = news_scan_required;
169                 news_class.rename_folder = news_rename_folder;
170                 news_class.remove_folder = news_remove_folder;
171
172                 /* Message functions */
173                 news_class.get_msginfo = news_get_msginfo;
174                 news_class.get_msginfos = news_get_msginfos;
175                 news_class.fetch_msg = news_fetch_msg;
176                 news_class.synchronise = news_synchronise;
177                 news_class.remove_msg = news_remove_msg;
178                 news_class.remove_cached_msg = news_remove_cached_msg;
179         };
180
181         return &news_class;
182 }
183
184 guint nntp_folder_get_refcnt(Folder *folder)
185 {
186         return ((NewsFolder *)folder)->refcnt;
187 }
188
189 void nntp_folder_ref(Folder *folder)
190 {
191         ((NewsFolder *)folder)->refcnt++;
192 }
193
194 void nntp_folder_unref(Folder *folder)
195 {
196         if (((NewsFolder *)folder)->refcnt > 0)
197                 ((NewsFolder *)folder)->refcnt--;
198 }
199
200 static int news_remove_msg               (Folder        *folder, 
201                                           FolderItem    *item, 
202                                           gint           msgnum)
203 {
204         gchar *path, *filename;
205
206         cm_return_val_if_fail(folder != NULL, -1);
207         cm_return_val_if_fail(item != NULL, -1);
208
209         path = folder_item_get_path(item);
210         if (!is_dir_exist(path))
211                 make_dir_hier(path);
212         
213         filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msgnum), NULL);
214         g_free(path);
215         claws_unlink(filename);
216         g_free(filename);
217         return 0;
218 }
219
220 static void news_folder_lock(NewsFolder *folder)
221 {
222         folder->lock_count++;
223 }
224
225 static void news_folder_unlock(NewsFolder *folder)
226 {
227         if (folder->lock_count > 0)
228                 folder->lock_count--;
229 }
230
231 int news_folder_locked(Folder *folder)
232 {
233         if (folder == NULL)
234                 return 0;
235
236         return NEWS_FOLDER(folder)->lock_count;
237 }
238
239 static Folder *news_folder_new(const gchar *name, const gchar *path)
240 {
241         Folder *folder;
242
243         folder = (Folder *)g_new0(NewsFolder, 1);
244         folder->klass = &news_class;
245         news_folder_init(folder, name, path);
246
247         return folder;
248 }
249
250 static void news_folder_destroy(Folder *folder)
251 {
252         gchar *dir;
253
254         while (nntp_folder_get_refcnt(folder) > 0)
255                 gtk_main_iteration();
256
257         dir = news_folder_get_path(folder);
258         if (is_dir_exist(dir))
259                 remove_dir_recursive(dir);
260         g_free(dir);
261
262         nntp_done(folder);
263         folder_remote_folder_destroy(REMOTE_FOLDER(folder));
264 }
265
266 static void news_folder_init(Folder *folder, const gchar *name,
267                              const gchar *path)
268 {
269         folder_remote_folder_init(folder, name, path);
270 }
271
272 static void news_session_destroy(Session *session)
273 {
274         NewsSession *news_session = NEWS_SESSION(session);
275
276         cm_return_if_fail(session != NULL);
277
278         if (news_session->group)
279                 g_free(news_session->group);
280 }
281
282 #ifdef USE_GNUTLS
283 static Session *news_session_new(Folder *folder, const gchar *server, gushort port,
284                                  const gchar *userid, const gchar *passwd,
285                                  SSLType ssl_type)
286 #else
287 static Session *news_session_new(Folder *folder, const gchar *server, gushort port,
288                                  const gchar *userid, const gchar *passwd)
289 #endif
290 {
291         NewsSession *session;
292         int r = 0;
293         cm_return_val_if_fail(server != NULL, NULL);
294
295         log_message(LOG_PROTOCOL, _("Account '%s': Connecting to NNTP server: %s...\n"),
296                                     folder->account->account_name, server);
297
298         session = g_new0(NewsSession, 1);
299         session_init(SESSION(session), folder->account, FALSE);
300         SESSION(session)->type             = SESSION_NEWS;
301         SESSION(session)->server           = g_strdup(server);
302         SESSION(session)->port             = port;
303         SESSION(session)->sock             = NULL;
304         SESSION(session)->destroy          = news_session_destroy;
305         
306         nntp_init(folder);
307
308 #ifdef USE_GNUTLS
309         if (ssl_type != SSL_NONE)
310                 r = nntp_threaded_connect_ssl(folder, server, port);
311         else
312 #endif
313                 r = nntp_threaded_connect(folder, server, port);
314         
315         if (r != NEWSNNTP_NO_ERROR) {
316                 log_error(LOG_PROTOCOL, _("Error logging in to %s:%d ...\n"), server, port);
317                 session_destroy(SESSION(session));
318                 return NULL;
319         }
320         
321         return SESSION(session);
322 }
323
324 static Session *news_session_new_for_folder(Folder *folder)
325 {
326         Session *session;
327         PrefsAccount *ac;
328         const gchar *userid = NULL;
329         gchar *passwd = NULL;
330         gushort port;
331         int r;
332
333         cm_return_val_if_fail(folder != NULL, NULL);
334         cm_return_val_if_fail(folder->account != NULL, NULL);
335
336         ac = folder->account;
337         if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
338                 userid = ac->userid;
339                 if (ac->passwd && ac->passwd[0])
340                         passwd = g_strdup(ac->passwd);
341                 else
342                         passwd = input_dialog_query_password_keep(ac->nntp_server,
343                                                                   userid,
344                                                                   &(ac->session_passwd));
345         }
346
347 #ifdef USE_GNUTLS
348         port = ac->set_nntpport ? ac->nntpport
349                 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
350         session = news_session_new(folder, ac->nntp_server, port, userid, passwd,
351                                    ac->ssl_nntp);
352 #else
353         if (ac->ssl_nntp != SSL_NONE) {
354                 if (alertpanel_full(_("Insecure connection"),
355                         _("This connection is configured to be secured "
356                           "using SSL, but SSL is not available in this "
357                           "build of Claws Mail. \n\n"
358                           "Do you want to continue connecting to this "
359                           "server? The communication would not be "
360                           "secure."),
361                           GTK_STOCK_CANCEL, _("Con_tinue connecting"), 
362                           NULL, FALSE, NULL, ALERT_WARNING,
363                           G_ALERTDEFAULT) != G_ALERTALTERNATE)
364                         return NULL;
365         }
366         port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
367         session = news_session_new(folder, ac->nntp_server, port, userid, passwd);
368 #endif
369
370         if (session != NULL)
371                 r = nntp_threaded_mode_reader(folder);
372         else
373                 r = NEWSNNTP_ERROR_CONNECTION_REFUSED;
374
375         if (r != NEWSNNTP_NO_ERROR) {
376             if (r == NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME) {
377                 /*
378                    FIX ME when libetpan implements 480 to indicate authorization
379                    is required to use this capability. Libetpan treats a 480 as a
380                    381 which is clearly wrong.
381                    RFC 4643 section 2.
382                    Response code 480
383                    Generic response
384                    Meaning: command unavailable until the client
385                    has authenticated itself.
386                 */
387                 /* if the server does not advertise the capability MODE-READER,
388                    we normally should not send MODE READER. However this can't
389                    hurt: a transit-only server returns 502 and closes the cnx.
390                    Ref.: http://tools.ietf.org/html/rfc3977#section-5.3
391                 */
392                 log_error(LOG_PROTOCOL, _("Libetpan does not support return code 480 "
393                 "so for now we choose to continue\n"));
394             }
395             else if (r == NEWSNNTP_ERROR_UNEXPECTED_RESPONSE) {
396                 /* if the server does not advertise the capability MODE-READER,
397                    we normally should not send MODE READER. However this can't
398                    hurt: a transit-only server returns 502 and closes the cnx.
399                    Ref.: http://tools.ietf.org/html/rfc3977#section-5.3
400                 */
401                 log_error(LOG_PROTOCOL, _("Mode reader failed, continuing nevertheless\n")); 
402             }
403             else {
404                 /* An error state bail out */
405                 log_error(LOG_PROTOCOL, _("Error creating session with %s:%d\n"), ac->nntp_server, port);
406                 session_destroy(SESSION(session));
407                 g_free(passwd);
408                 if (ac->session_passwd) {
409                         g_free(ac->session_passwd);
410                         ac->session_passwd = NULL;
411                 }
412                 return NULL;
413             }
414         }
415
416         if ((session != NULL) && ac->use_nntp_auth) { /* FIXME:  && ac->use_nntp_auth_onconnect */
417                 if (nntp_threaded_login(folder, userid, passwd) !=
418                         NEWSNNTP_NO_ERROR) {
419                         log_error(LOG_PROTOCOL, _("Error authenticating to %s:%d ...\n"), ac->nntp_server, port);
420                         session_destroy(SESSION(session));
421                         g_free(passwd);
422                         if (ac->session_passwd) {
423                                 g_free(ac->session_passwd);
424                                 ac->session_passwd = NULL;
425                         }
426                         return NULL;
427                 }
428         }
429         g_free(passwd);
430
431         return session;
432 }
433
434 static NewsSession *news_session_get(Folder *folder)
435 {
436         RemoteFolder *rfolder = REMOTE_FOLDER(folder);
437         struct tm lt;
438         int r;
439         
440         cm_return_val_if_fail(folder != NULL, NULL);
441         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
442         cm_return_val_if_fail(folder->account != NULL, NULL);
443
444         if (prefs_common.work_offline && 
445             !inc_offline_should_override(FALSE,
446                 _("Claws Mail needs network access in order "
447                   "to access the News server."))) {
448                 return NULL;
449         }
450
451         if (!rfolder->session) {
452                 rfolder->session = news_session_new_for_folder(folder);
453                 return NEWS_SESSION(rfolder->session);
454         }
455
456         /* Handle port change (also ssl/nossl change) without needing to
457          * restart application. */
458         if (rfolder->session->port != folder->account->nntpport) {
459                 session_destroy(rfolder->session);
460                 rfolder->session = news_session_new_for_folder(folder);
461                 goto newsession;
462         }
463         
464         if (time(NULL) - rfolder->session->last_access_time <
465                 SESSION_TIMEOUT_INTERVAL) {
466                 return NEWS_SESSION(rfolder->session);
467         }
468
469         if ((r = nntp_threaded_date(folder, &lt)) != NEWSNNTP_NO_ERROR) {
470                 if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED &&
471                     r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) {
472                         log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been"
473                               " disconnected. Reconnecting...\n"),
474                             folder->account->nntp_server,
475                             folder->account->set_nntpport ?
476                             folder->account->nntpport : NNTP_PORT);
477                         session_destroy(rfolder->session);
478                         rfolder->session = news_session_new_for_folder(folder);
479                 }
480         }
481
482 newsession:
483         if (rfolder->session)
484                 session_set_access_time(rfolder->session);
485
486         return NEWS_SESSION(rfolder->session);
487 }
488
489 static void news_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
490 {
491         gchar *path, *filename;
492
493         path = folder_item_get_path(item);
494
495         if (!is_dir_exist(path)) {
496                 g_free(path);
497                 return;
498         }
499
500         filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
501         g_free(path);
502
503         if (is_file_exist(filename)) {
504                 claws_unlink(filename);
505         }
506         g_free(filename);
507 }
508
509 static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
510 {
511         gchar *path, *filename;
512         NewsSession *session;
513         gint ok;
514
515         cm_return_val_if_fail(folder != NULL, NULL);
516         cm_return_val_if_fail(item != NULL, NULL);
517
518         path = folder_item_get_path(item);
519         if (!is_dir_exist(path))
520                 make_dir_hier(path);
521         filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
522         g_free(path);
523
524         if (is_file_exist(filename)) {
525                 debug_print("article %d has been already cached.\n", num);
526                 return filename;
527         }
528
529         session = news_session_get(folder);
530         if (!session) {
531                 g_free(filename);
532                 return NULL;
533         }
534
535         ok = news_select_group(folder, item->path, NULL, NULL, NULL);
536         if (ok != NEWSNNTP_NO_ERROR) {
537                 if (ok == NEWSNNTP_ERROR_STREAM) {
538                         session_destroy(SESSION(session));
539                         REMOTE_FOLDER(folder)->session = NULL;
540                 }
541                 g_free(filename);
542                 return NULL;
543         }
544
545         debug_print("getting article %d...\n", num);
546         ok = news_get_article(folder,
547                               num, filename);
548         if (ok != NEWSNNTP_NO_ERROR) {
549                 g_warning("can't read article %d\n", num);
550                 if (ok == NEWSNNTP_ERROR_STREAM) {
551                         session_destroy(SESSION(session));
552                         REMOTE_FOLDER(folder)->session = NULL;
553                 }
554                 g_free(filename);
555                 return NULL;
556         }
557         GTK_EVENTS_FLUSH();
558         return filename;
559 }
560
561 static NewsGroupInfo *news_group_info_new(const gchar *name,
562                                           gint first, gint last, gchar type)
563 {
564         NewsGroupInfo *ginfo;
565
566         ginfo = g_new(NewsGroupInfo, 1);
567         ginfo->name = g_strdup(name);
568         ginfo->first = first;
569         ginfo->last = last;
570         ginfo->type = type;
571
572         return ginfo;
573 }
574
575 static void news_group_info_free(NewsGroupInfo *ginfo)
576 {
577         g_free(ginfo->name);
578         g_free(ginfo);
579 }
580
581 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
582                                     NewsGroupInfo *ginfo2)
583 {
584         return g_ascii_strcasecmp(ginfo1->name, ginfo2->name);
585 }
586
587 GSList *news_get_group_list(Folder *folder)
588 {
589         gchar *path, *filename;
590         FILE *fp;
591         GSList *list = NULL;
592         GSList *last = NULL;
593         gchar buf[BUFFSIZE];
594
595         cm_return_val_if_fail(folder != NULL, NULL);
596         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
597
598         path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
599         if (!is_dir_exist(path))
600                 make_dir_hier(path);
601         filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
602         g_free(path);
603
604         if ((fp = g_fopen(filename, "rb")) == NULL) {
605                 NewsSession *session;
606                 gint ok;
607                 clist *grouplist = NULL;
608                 clistiter *cur;
609                 fp = g_fopen(filename, "wb");
610                 
611                 if (!fp) {
612                         g_free(filename);
613                         return NULL;
614                 }
615                 session = news_session_get(folder);
616                 if (!session) {
617                         fclose(fp);
618                         g_free(filename);
619                         return NULL;
620                 }
621
622                 ok = nntp_threaded_list(folder, &grouplist);
623                 
624                 if (ok != NEWSNNTP_NO_ERROR) {
625                         if (ok == NEWSNNTP_ERROR_STREAM) {
626                                 session_destroy(SESSION(session));
627                                 REMOTE_FOLDER(folder)->session = NULL;
628                         }
629                         fclose(fp);
630                         g_free(filename);
631                         return NULL;
632                 }
633                 
634                 if (grouplist) {
635                         for (cur = clist_begin(grouplist); cur; cur = clist_next(cur)) {
636                                 struct newsnntp_group_info *info = (struct newsnntp_group_info *)
637                                                                         clist_content(cur);
638                                 if (fprintf(fp, "%s %d %d %c\n",
639                                         info->grp_name,
640                                         info->grp_last,
641                                         info->grp_first,
642                                         info->grp_type) < 0) {
643                                         log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
644                                         session_destroy(SESSION(session));
645                                         REMOTE_FOLDER(folder)->session = NULL;
646                                         fclose(fp);
647                                         g_free(filename);
648                                         newsnntp_list_free(grouplist);
649                                         return NULL;
650                                 }
651                         }
652                         newsnntp_list_free(grouplist);
653                 }
654                 if (fclose(fp) == EOF) {
655                         log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
656                         session_destroy(SESSION(session));
657                         REMOTE_FOLDER(folder)->session = NULL;
658                         g_free(filename);
659                         return NULL;
660                 }
661
662                 if ((fp = g_fopen(filename, "rb")) == NULL) {
663                         FILE_OP_ERROR(filename, "fopen");
664                         g_free(filename);
665                         return NULL;
666                 }
667         }
668
669         while (fgets(buf, sizeof(buf), fp) != NULL) {
670                 gchar *p = buf;
671                 gchar *name;
672                 gint last_num;
673                 gint first_num;
674                 gchar type;
675                 NewsGroupInfo *ginfo;
676
677                 p = strchr(p, ' ');
678                 if (!p) continue;
679                 *p = '\0';
680                 p++;
681                 name = buf;
682
683                 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
684                         continue;
685
686                 ginfo = news_group_info_new(name, first_num, last_num, type);
687
688                 if (!last)
689                         last = list = g_slist_append(NULL, ginfo);
690                 else {
691                         last = g_slist_append(last, ginfo);
692                         last = last->next;
693                 }
694         }
695
696         fclose(fp);
697         g_free(filename);
698
699         list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
700
701         return list;
702 }
703
704 void news_group_list_free(GSList *group_list)
705 {
706         GSList *cur;
707
708         if (!group_list) return;
709
710         for (cur = group_list; cur != NULL; cur = cur->next)
711                 news_group_info_free((NewsGroupInfo *)cur->data);
712         g_slist_free(group_list);
713 }
714
715 void news_remove_group_list_cache(Folder *folder)
716 {
717         gchar *path, *filename;
718
719         cm_return_if_fail(folder != NULL);
720         cm_return_if_fail(FOLDER_CLASS(folder) == &news_class);
721
722         path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
723         filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
724         g_free(path);
725
726         if (is_file_exist(filename)) {
727                 if (remove(filename) < 0)
728                         FILE_OP_ERROR(filename, "remove");
729         }
730         g_free(filename);
731 }
732
733 gint news_post(Folder *folder, const gchar *file)
734 {
735         gint ok;
736         char *contents = file_read_to_str_no_recode(file);
737         NewsSession *session;
738
739         cm_return_val_if_fail(folder != NULL, -1);
740         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
741         cm_return_val_if_fail(contents != NULL, -1);
742         
743         session = news_session_get(folder);
744         if (!session)  {
745                 g_free(contents);
746                 return -1;
747         }
748         
749         ok = nntp_threaded_post(folder, contents, strlen(contents));
750
751         g_free(contents);
752
753         if (ok == NEWSNNTP_ERROR_STREAM) {
754                 session_destroy(SESSION(session));
755                 REMOTE_FOLDER(folder)->session = NULL;
756         }
757
758         return (ok == NEWSNNTP_NO_ERROR ? 0 : -1);
759 }
760
761 static gint news_get_article(Folder *folder, gint num, gchar *filename)
762 {
763         size_t len;
764         char *result = NULL;
765         int r;
766         
767         r = nntp_threaded_article(folder, num, &result, &len);
768         
769         if (r == NEWSNNTP_NO_ERROR) {
770                 if (str_write_to_file(result, filename) < 0)
771                         return -1;
772                 g_free(result);
773         }
774         
775         return r;
776 }
777
778 /**
779  * news_select_group:
780  * @session: Active NNTP session.
781  * @group: Newsgroup name.
782  * @num: Estimated number of articles.
783  * @first: First article number.
784  * @last: Last article number.
785  *
786  * Select newsgroup @group with the GROUP command if it is not already
787  * selected in @session, or article numbers need to be returned.
788  *
789  * Return value: NNTP result code.
790  **/
791 static gint news_select_group(Folder *folder, const gchar *group,
792                               gint *num, gint *first, gint *last)
793 {
794         gint ok;
795         gint num_, first_, last_;
796         struct newsnntp_group_info *info = NULL;
797         NewsSession *session = NEWS_SESSION(news_session_get(folder));
798
799         cm_return_val_if_fail(session != NULL, -1);
800         
801         if (!num || !first || !last) {
802                 if (session->group && g_ascii_strcasecmp(session->group, group) == 0)
803                         return NEWSNNTP_NO_ERROR;
804                 num = &num_;
805                 first = &first_;
806                 last = &last_;
807         }
808
809         g_free(session->group);
810         session->group = NULL;
811
812         ok = nntp_threaded_group(folder, group, &info);
813         
814         if (ok == NEWSNNTP_NO_ERROR && info) {
815                 session->group = g_strdup(group);
816                 *num = info->grp_first;
817                 *first = info->grp_first;
818                 *last = info->grp_last;
819                 newsnntp_group_free(info);
820         } else {
821                 log_warning(LOG_PROTOCOL, _("couldn't select group: %s\n"), group);
822         }
823         return ok;
824 }
825
826 static MsgInfo *news_parse_xover(struct newsnntp_xover_resp_item *item)
827 {
828         MsgInfo *msginfo;
829
830         /* set MsgInfo */
831         msginfo = procmsg_msginfo_new();
832         msginfo->msgnum = item->ovr_article;
833         msginfo->size = item->ovr_size;
834
835         msginfo->date = g_strdup(item->ovr_date);
836         msginfo->date_t = procheader_date_parse(NULL, item->ovr_date, 0);
837
838         msginfo->from = conv_unmime_header(item->ovr_author, NULL, TRUE);
839         msginfo->fromname = procheader_get_fromname(msginfo->from);
840
841         msginfo->subject = conv_unmime_header(item->ovr_subject, NULL, TRUE);
842
843         remove_return(msginfo->from);
844         remove_return(msginfo->fromname);
845         remove_return(msginfo->subject);
846
847         if (item->ovr_message_id) {
848                 gchar *tmp = g_strdup(item->ovr_message_id);
849                 extract_parenthesis(tmp, '<', '>');
850                 remove_space(tmp);
851                 if (*tmp != '\0')
852                         msginfo->msgid = g_strdup(tmp);
853                 g_free(tmp);
854         }                        
855
856         /* FIXME: this is a quick fix; references' meaning was changed
857          * into having the actual list of references in the References: header.
858          * We need a GSList here, so msginfo_free() and msginfo_copy() can do 
859          * their things properly. */ 
860         if (item->ovr_references && *(item->ovr_references)) {   
861                 gchar **ref_tokens = g_strsplit(item->ovr_references, " ", -1);
862                 guint i = 0;
863                 char *tmp;
864                 char *p;
865                 while (ref_tokens[i]) {
866                         gchar *cur_ref = ref_tokens[i];
867                         msginfo->references = references_list_append(msginfo->references, 
868                                         cur_ref);
869                         i++;
870                 }
871                 g_strfreev(ref_tokens);
872                 
873                 tmp = g_strdup(item->ovr_references);
874                 eliminate_parenthesis(tmp, '(', ')');
875                 if ((p = strrchr(tmp, '<')) != NULL) {
876                         extract_parenthesis(p, '<', '>');
877                         remove_space(p);
878                         if (*p != '\0')
879                                 msginfo->inreplyto = g_strdup(p);
880                 }
881                 g_free(tmp);
882         } 
883
884         return msginfo;
885 }
886
887 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
888 {
889         gchar * tmp;
890         FILE * tmpfp;
891         gchar buf[BUFFSIZE];
892
893         tmp = g_strdup_printf("%s%ccancel%p", get_tmp_dir(),
894                               G_DIR_SEPARATOR, msginfo);
895         if (tmp == NULL)
896                 return -1;
897
898         if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
899                 FILE_OP_ERROR(tmp, "fopen");
900                 return -1;
901         }
902         if (change_file_mode_rw(tmpfp, tmp) < 0) {
903                 FILE_OP_ERROR(tmp, "chmod");
904                 g_warning("can't change file mode\n");
905         }
906         
907         get_rfc822_date(buf, sizeof(buf));
908         if (fprintf(tmpfp, "From: %s\r\n"
909                        "Newsgroups: %s\r\n"
910                        "Subject: cmsg cancel <%s>\r\n"
911                        "Control: cancel <%s>\r\n"
912                        "Approved: %s\r\n"
913                        "X-Cancelled-by: %s\r\n"
914                        "Date: %s\r\n"
915                        "\r\n"
916                        "removed with Claws Mail\r\n",
917                        msginfo->from,
918                        msginfo->newsgroups,
919                        msginfo->msgid,
920                        msginfo->msgid,
921                        msginfo->from,
922                        msginfo->from,
923                        buf) < 0) {
924                 FILE_OP_ERROR(tmp, "fprintf");
925                 fclose(tmpfp);
926                 claws_unlink(tmp);
927                 g_free(tmp);
928                 return -1;
929         }
930
931         if (fclose(tmpfp) == EOF) {
932                 FILE_OP_ERROR(tmp, "fclose");
933                 claws_unlink(tmp);
934                 g_free(tmp);
935                 return -1;
936         }
937
938         news_post(folder, tmp);
939         remove(tmp);
940
941         g_free(tmp);
942
943         return 0;
944 }
945
946 static gchar *news_folder_get_path(Folder *folder)
947 {
948         gchar *folder_path;
949
950         cm_return_val_if_fail(folder->account != NULL, NULL);
951
952         folder_path = g_strconcat(get_news_cache_dir(),
953                                   G_DIR_SEPARATOR_S,
954                                   folder->account->nntp_server,
955                                   NULL);
956         return folder_path;
957 }
958
959 static gchar *news_item_get_path(Folder *folder, FolderItem *item)
960 {
961         gchar *folder_path, *path;
962
963         cm_return_val_if_fail(folder != NULL, NULL);
964         cm_return_val_if_fail(item != NULL, NULL);
965         folder_path = news_folder_get_path(folder);
966
967         cm_return_val_if_fail(folder_path != NULL, NULL);
968         if (g_path_is_absolute(folder_path)) {
969                 if (item->path)
970                         path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
971                                            item->path, NULL);
972                 else
973                         path = g_strdup(folder_path);
974         } else {
975                 if (item->path)
976                         path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
977                                            folder_path, G_DIR_SEPARATOR_S,
978                                            item->path, NULL);
979                 else
980                         path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
981                                            folder_path, NULL);
982         }
983         g_free(folder_path);
984 #ifdef G_OS_WIN32
985         while (strchr(path, '/'))
986                 *strchr(path, '/') = '\\';
987 #endif
988         return path;
989 }
990
991 static gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list, gboolean *old_uids_valid)
992 {
993         NewsSession *session;
994         gint i, ok, num, first, last, nummsgs = 0;
995         gchar *dir;
996
997         cm_return_val_if_fail(item != NULL, -1);
998         cm_return_val_if_fail(item->folder != NULL, -1);
999         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
1000
1001         session = news_session_get(folder);
1002         cm_return_val_if_fail(session != NULL, -1);
1003
1004         *old_uids_valid = TRUE;
1005         
1006         news_folder_lock(NEWS_FOLDER(item->folder));
1007
1008         ok = news_select_group(folder, item->path, &num, &first, &last);
1009         if (ok != NEWSNNTP_NO_ERROR) {
1010                 log_warning(LOG_PROTOCOL, _("couldn't set group: %s\n"), item->path);
1011                 news_folder_unlock(NEWS_FOLDER(item->folder));
1012                 return -1;
1013         }
1014
1015         dir = news_folder_get_path(folder);
1016         if (num <= 0)
1017                 remove_all_numbered_files(dir);
1018         else if (last < first)
1019                 log_warning(LOG_PROTOCOL, _("invalid article range: %d - %d\n"),
1020                             first, last);
1021         else {
1022                 for (i = first; i <= last; i++) {
1023                         *msgnum_list = g_slist_prepend(*msgnum_list, 
1024                                                        GINT_TO_POINTER(i));
1025                         nummsgs++;
1026                 }
1027                 debug_print("removing old messages from %d to %d in %s\n",
1028                             first, last, dir);
1029                 remove_numbered_files(dir, 1, first - 1);
1030         }
1031         g_free(dir);
1032         news_folder_unlock(NEWS_FOLDER(item->folder));
1033         return nummsgs;
1034 }
1035
1036 static void news_set_msg_flags(FolderItem *item, MsgInfo *msginfo)
1037 {
1038         msginfo->flags.tmp_flags = 0;
1039         if (item->folder->account->mark_crosspost_read && msginfo->msgid) {
1040                 if (item->folder->newsart &&
1041                     g_hash_table_lookup(item->folder->newsart, msginfo->msgid) != NULL) {
1042                         msginfo->flags.perm_flags = MSG_COLORLABEL_TO_FLAGS(item->folder->account->crosspost_col);
1043                                 
1044                 } else {
1045                         if (!item->folder->newsart) 
1046                                 item->folder->newsart = g_hash_table_new(g_str_hash, g_str_equal);
1047                         g_hash_table_insert(item->folder->newsart,
1048                                         g_strdup(msginfo->msgid), GINT_TO_POINTER(1));
1049                         msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
1050                 }
1051         } else {
1052                 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
1053         }
1054 }
1055
1056 static void news_get_extra_fields(NewsSession *session, FolderItem *item, GSList *msglist)
1057 {
1058         MsgInfo *msginfo = NULL;
1059         gint ok;
1060         GSList *cur;
1061         clist *hdrlist = NULL;
1062         clistiter *hdr;
1063         gint first = -1, last = -1;
1064         GHashTable *hash_table;
1065         
1066         cm_return_if_fail(session != NULL);
1067         cm_return_if_fail(item != NULL);
1068         cm_return_if_fail(item->folder != NULL);
1069         cm_return_if_fail(FOLDER_CLASS(item->folder) == &news_class);
1070
1071         news_folder_lock(NEWS_FOLDER(item->folder));
1072
1073         hash_table = g_hash_table_new(g_direct_hash, g_direct_equal);
1074         
1075         for (cur = msglist; cur; cur = cur->next) {
1076                 msginfo = (MsgInfo *)cur->data;
1077                 if (first == -1 || msginfo->msgnum < first)
1078                         first = msginfo->msgnum;
1079                 if (last == -1 || msginfo->msgnum > last)
1080                         last = msginfo->msgnum;
1081                 g_hash_table_insert(hash_table,
1082                                 GINT_TO_POINTER(msginfo->msgnum), msginfo);
1083         }
1084
1085 /* Newsgroups */
1086         ok = nntp_threaded_xhdr(item->folder, "newsgroups", first, last, &hdrlist);
1087
1088         if (ok != NEWSNNTP_NO_ERROR) {
1089                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1090                 if (ok == NEWSNNTP_ERROR_STREAM) {
1091                         session_destroy(SESSION(session));
1092                         REMOTE_FOLDER(item->folder)->session = NULL;
1093                 }
1094                 news_folder_unlock(NEWS_FOLDER(item->folder));
1095                 return;
1096         }
1097
1098         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1099                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1100                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1101                 if (msginfo) {
1102                         if (msginfo->newsgroups)
1103                                 g_free(msginfo->newsgroups);
1104                         msginfo->newsgroups = g_strdup(hdrval->hdr_value);
1105                 }
1106         }
1107         newsnntp_xhdr_free(hdrlist);
1108         
1109 /* To */
1110         ok = nntp_threaded_xhdr(item->folder, "to", first, last, &hdrlist);
1111
1112         if (ok != NEWSNNTP_NO_ERROR) {
1113                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1114                 if (ok == NEWSNNTP_ERROR_STREAM) {
1115                         session_destroy(SESSION(session));
1116                         REMOTE_FOLDER(item->folder)->session = NULL;
1117                 }
1118                 news_folder_unlock(NEWS_FOLDER(item->folder));
1119                 return;
1120         }
1121
1122         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1123                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1124                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1125                 if (msginfo) {
1126                         if (msginfo->to)
1127                                 g_free(msginfo->to);
1128                         msginfo->to = g_strdup(hdrval->hdr_value);
1129                 }
1130         }
1131         newsnntp_xhdr_free(hdrlist);
1132         
1133 /* Cc */
1134         ok = nntp_threaded_xhdr(item->folder, "cc", first, last, &hdrlist);
1135
1136         if (ok != NEWSNNTP_NO_ERROR) {
1137                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1138                 if (ok == NEWSNNTP_ERROR_STREAM) {
1139                         session_destroy(SESSION(session));
1140                         REMOTE_FOLDER(item->folder)->session = NULL;
1141                 }
1142                 news_folder_unlock(NEWS_FOLDER(item->folder));
1143                 return;
1144         }
1145
1146         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1147                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1148                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1149                 if (msginfo) {
1150                         if (msginfo->cc)
1151                                 g_free(msginfo->cc);
1152                         msginfo->cc = g_strdup(hdrval->hdr_value);
1153                 }
1154         }
1155         newsnntp_xhdr_free(hdrlist);
1156         
1157
1158         g_hash_table_destroy(hash_table);
1159         news_folder_unlock(NEWS_FOLDER(item->folder));
1160 }
1161
1162 static GSList *news_get_msginfos_for_range(NewsSession *session, FolderItem *item, guint begin, guint end)
1163 {
1164         GSList *newlist = NULL;
1165         GSList *llast = NULL;
1166         MsgInfo *msginfo;
1167         gint ok;
1168         clist *msglist = NULL;
1169         clistiter *cur;
1170         cm_return_val_if_fail(session != NULL, NULL);
1171         cm_return_val_if_fail(item != NULL, NULL);
1172
1173         log_message(LOG_PROTOCOL, _("getting xover %d - %d in %s...\n"),
1174                     begin, end, item->path);
1175
1176         news_folder_lock(NEWS_FOLDER(item->folder));
1177         
1178         ok = news_select_group(item->folder, item->path, NULL, NULL, NULL);
1179         if (ok != NEWSNNTP_NO_ERROR) {
1180                 log_warning(LOG_PROTOCOL, _("couldn't set group: %s\n"), item->path);
1181                 news_folder_unlock(NEWS_FOLDER(item->folder));
1182                 return NULL;
1183         }
1184
1185         ok = nntp_threaded_xover(item->folder, begin, end, NULL, &msglist);
1186         
1187         if (ok != NEWSNNTP_NO_ERROR) {
1188                 log_warning(LOG_PROTOCOL, _("couldn't get xover\n"));
1189                 if (ok == NEWSNNTP_ERROR_STREAM) {
1190                         session_destroy(SESSION(session));
1191                         REMOTE_FOLDER(item->folder)->session = NULL;
1192                 }
1193                 news_folder_unlock(NEWS_FOLDER(item->folder));
1194                 return NULL;
1195         }
1196
1197         if (msglist) {
1198                 for (cur = clist_begin(msglist); cur; cur = clist_next(cur)) {
1199                         struct newsnntp_xover_resp_item *ritem = (struct newsnntp_xover_resp_item *)clist_content(cur);
1200                         msginfo = news_parse_xover(ritem);
1201                         
1202                         if (!msginfo) {
1203                                 log_warning(LOG_PROTOCOL, _("invalid xover line\n"));
1204                                 continue;
1205                         }
1206
1207                         msginfo->folder = item;
1208                         news_set_msg_flags(item, msginfo);
1209                         msginfo->flags.tmp_flags |= MSG_NEWS;
1210
1211                         if (!newlist)
1212                                 llast = newlist = g_slist_append(newlist, msginfo);
1213                         else {
1214                                 llast = g_slist_append(llast, msginfo);
1215                                 llast = llast->next;
1216                         }
1217                 }
1218                 newsnntp_xover_resp_list_free(msglist);
1219         }
1220
1221         news_folder_unlock(NEWS_FOLDER(item->folder));
1222
1223         session_set_access_time(SESSION(session));
1224
1225         news_get_extra_fields(session, item, newlist);
1226         
1227         return newlist;
1228 }
1229
1230 static MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
1231 {
1232         GSList *msglist = NULL;
1233         NewsSession *session;
1234         MsgInfo *msginfo = NULL;
1235
1236         session = news_session_get(folder);
1237         cm_return_val_if_fail(session != NULL, NULL);
1238         cm_return_val_if_fail(item != NULL, NULL);
1239         cm_return_val_if_fail(item->folder != NULL, NULL);
1240         cm_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
1241
1242         msglist = news_get_msginfos_for_range(session, item, num, num);
1243  
1244         if (msglist)
1245                 msginfo = msglist->data;
1246         
1247         g_slist_free(msglist);
1248         
1249         return msginfo;
1250 }
1251
1252 static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1253 {
1254         NewsSession *session;
1255         GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1256         guint first, last, next;
1257         guint tofetch, fetched;
1258         
1259         cm_return_val_if_fail(folder != NULL, NULL);
1260         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1261         cm_return_val_if_fail(msgnum_list != NULL, NULL);
1262         cm_return_val_if_fail(item != NULL, NULL);
1263         
1264         session = news_session_get(folder);
1265         cm_return_val_if_fail(session != NULL, NULL);
1266
1267         tmp_msgnum_list = g_slist_copy(msgnum_list);
1268         tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
1269
1270         progressindicator_start(PROGRESS_TYPE_NETWORK);
1271         tofetch = g_slist_length(tmp_msgnum_list);
1272         fetched = 0;
1273
1274         first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1275         last = first;
1276         
1277         news_folder_lock(NEWS_FOLDER(item->folder));
1278         
1279         for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1280                 next = GPOINTER_TO_INT(elem->data);
1281                 if(next != (last + 1)) {
1282 /*                      session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1283                         session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1284 */
1285                         tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1286                         msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1287                         fetched = last - first + 1;
1288                         first = next;
1289                 }
1290                 last = next;
1291         }
1292         
1293         news_folder_unlock(NEWS_FOLDER(item->folder));
1294         
1295 /*      session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1296         session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1297 */
1298         tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1299         msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1300
1301         g_slist_free(tmp_msgnum_list);
1302         
1303         progressindicator_stop(PROGRESS_TYPE_NETWORK);
1304
1305         return msginfo_list;
1306 }
1307
1308 static gboolean news_scan_required(Folder *folder, FolderItem *item)
1309 {
1310         return TRUE;
1311 }
1312
1313 void news_synchronise(FolderItem *item, gint days) 
1314 {
1315         news_gtk_synchronise(item, days);
1316 }
1317
1318 static gint news_rename_folder(Folder *folder, FolderItem *item,
1319                                 const gchar *name)
1320 {
1321         gchar *path;
1322          
1323         cm_return_val_if_fail(folder != NULL, -1);
1324         cm_return_val_if_fail(item != NULL, -1);
1325         cm_return_val_if_fail(item->path != NULL, -1);
1326         cm_return_val_if_fail(name != NULL, -1);
1327
1328         path = folder_item_get_path(item);
1329         if (!is_dir_exist(path))
1330                 make_dir_hier(path);
1331
1332         g_free(item->name);
1333         item->name = g_strdup(name);
1334
1335         return 0;
1336 }
1337
1338 static gint news_remove_folder(Folder *folder, FolderItem *item)
1339 {
1340         gchar *path;
1341
1342         cm_return_val_if_fail(folder != NULL, -1);
1343         cm_return_val_if_fail(item != NULL, -1);
1344         cm_return_val_if_fail(item->path != NULL, -1);
1345
1346         path = folder_item_get_path(item);
1347         if (remove_dir_recursive(path) < 0) {
1348                 g_warning("can't remove directory `%s'\n", path);
1349                 g_free(path);
1350                 return -1;
1351         }
1352
1353         g_free(path);
1354         folder_item_remove(item);
1355         return 0;
1356 }
1357
1358 #else
1359 #include <glib.h>
1360 #include <glib/gi18n.h>
1361 #include <gtk/gtk.h>
1362 #include "folder.h"
1363 #include "alertpanel.h"
1364
1365 static FolderClass news_class;
1366
1367 static void warn_etpan(void)
1368 {
1369         static gboolean missing_news_warning = TRUE;
1370         if (missing_news_warning) {
1371                 missing_news_warning = FALSE;
1372                 alertpanel_error(
1373                         _("You have one or more News accounts "
1374                           "defined. However this version of "
1375                           "Claws Mail has been built without "
1376                           "News support; your News account(s) are "
1377                           "disabled.\n\n"
1378                           "You probably need to "
1379                           "install libetpan and recompile "
1380                           "Claws Mail."));
1381         }
1382 }
1383 static Folder *news_folder_new(const gchar *name, const gchar *path)
1384 {
1385         warn_etpan();
1386         return NULL;
1387 }
1388 void news_group_list_free(GSList *group_list)
1389 {
1390         warn_etpan();
1391 }
1392 void news_remove_group_list_cache(Folder *folder)
1393 {
1394         warn_etpan();
1395 }
1396 int news_folder_locked(Folder *folder)
1397 {
1398         warn_etpan();
1399         return 0;
1400 }
1401 gint news_post(Folder *folder, const gchar *file)
1402 {
1403         warn_etpan();
1404         return -1;
1405 }
1406
1407 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
1408 {
1409         warn_etpan();
1410         return -1;
1411 }
1412
1413 GSList *news_get_group_list(Folder *folder)
1414 {
1415         warn_etpan();
1416         return NULL;
1417 }
1418
1419
1420 FolderClass *news_get_class(void)
1421 {
1422         if (news_class.idstr == NULL) {
1423                 news_class.type = F_NEWS;
1424                 news_class.idstr = "news";
1425                 news_class.uistr = "News";
1426
1427                 /* Folder functions */
1428                 news_class.new_folder = news_folder_new;
1429         };
1430
1431         return &news_class;
1432 }
1433
1434
1435 #endif