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