c79a6bec5aed483c7e34991125a80fb36b4a8eae
[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
332         cm_return_val_if_fail(folder != NULL, NULL);
333         cm_return_val_if_fail(folder->account != NULL, NULL);
334
335         ac = folder->account;
336         if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
337                 userid = ac->userid;
338                 if (ac->passwd && ac->passwd[0])
339                         passwd = g_strdup(ac->passwd);
340                 else
341                         passwd = input_dialog_query_password_keep(ac->nntp_server,
342                                                                   userid,
343                                                                   &(ac->session_passwd));
344         }
345
346 #ifdef USE_GNUTLS
347         port = ac->set_nntpport ? ac->nntpport
348                 : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
349         session = news_session_new(folder, ac->nntp_server, port, userid, passwd,
350                                    ac->ssl_nntp);
351 #else
352         if (ac->ssl_nntp != SSL_NONE) {
353                 if (alertpanel_full(_("Insecure connection"),
354                         _("This connection is configured to be secured "
355                           "using SSL, but SSL is not available in this "
356                           "build of Claws Mail. \n\n"
357                           "Do you want to continue connecting to this "
358                           "server? The communication would not be "
359                           "secure."),
360                           GTK_STOCK_CANCEL, _("Con_tinue connecting"), 
361                           NULL, FALSE, NULL, ALERT_WARNING,
362                           G_ALERTDEFAULT) != G_ALERTALTERNATE)
363                         return NULL;
364         }
365         port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
366         session = news_session_new(folder, ac->nntp_server, port, userid, passwd);
367 #endif
368
369         if ((session != NULL) && ac->use_nntp_auth) { /* FIXME:  && ac->use_nntp_auth_onconnect */
370                 if (nntp_threaded_login(folder, userid, passwd) !=
371                         NEWSNNTP_NO_ERROR) {
372                         log_error(LOG_PROTOCOL, _("Error authenticating to %s:%d ...\n"), ac->nntp_server, port);
373                         session_destroy(SESSION(session));
374                         g_free(passwd);
375                         if (ac->session_passwd) {
376                                 g_free(ac->session_passwd);
377                                 ac->session_passwd = NULL;
378                         }
379                         return NULL;
380                 }
381         }
382         g_free(passwd);
383
384         return session;
385 }
386
387 static NewsSession *news_session_get(Folder *folder)
388 {
389         RemoteFolder *rfolder = REMOTE_FOLDER(folder);
390         struct tm lt;
391         int r;
392         
393         cm_return_val_if_fail(folder != NULL, NULL);
394         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
395         cm_return_val_if_fail(folder->account != NULL, NULL);
396
397         if (prefs_common.work_offline && 
398             !inc_offline_should_override(FALSE,
399                 _("Claws Mail needs network access in order "
400                   "to access the News server."))) {
401                 return NULL;
402         }
403
404         if (!rfolder->session) {
405                 rfolder->session = news_session_new_for_folder(folder);
406                 return NEWS_SESSION(rfolder->session);
407         }
408
409         /* Handle port change (also ssl/nossl change) without needing to
410          * restart application. */
411         if (rfolder->session->port != folder->account->nntpport) {
412                 session_destroy(rfolder->session);
413                 rfolder->session = news_session_new_for_folder(folder);
414                 goto newsession;
415         }
416         
417         if (time(NULL) - rfolder->session->last_access_time <
418                 SESSION_TIMEOUT_INTERVAL) {
419                 return NEWS_SESSION(rfolder->session);
420         }
421
422         if ((r = nntp_threaded_date(folder, &lt)) != NEWSNNTP_NO_ERROR) {
423                 if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED &&
424                     r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) {
425                         log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been"
426                               " disconnected. Reconnecting...\n"),
427                             folder->account->nntp_server,
428                             folder->account->set_nntpport ?
429                             folder->account->nntpport : NNTP_PORT);
430                         session_destroy(rfolder->session);
431                         rfolder->session = news_session_new_for_folder(folder);
432                 }
433         }
434
435 newsession:
436         if (rfolder->session)
437                 session_set_access_time(rfolder->session);
438
439         return NEWS_SESSION(rfolder->session);
440 }
441
442 static void news_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
443 {
444         gchar *path, *filename;
445
446         path = folder_item_get_path(item);
447
448         if (!is_dir_exist(path)) {
449                 g_free(path);
450                 return;
451         }
452
453         filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
454         g_free(path);
455
456         if (is_file_exist(filename)) {
457                 claws_unlink(filename);
458         }
459         g_free(filename);
460 }
461
462 static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
463 {
464         gchar *path, *filename;
465         NewsSession *session;
466         gint ok;
467
468         cm_return_val_if_fail(folder != NULL, NULL);
469         cm_return_val_if_fail(item != NULL, NULL);
470
471         path = folder_item_get_path(item);
472         if (!is_dir_exist(path))
473                 make_dir_hier(path);
474         filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
475         g_free(path);
476
477         if (is_file_exist(filename)) {
478                 debug_print("article %d has been already cached.\n", num);
479                 return filename;
480         }
481
482         session = news_session_get(folder);
483         if (!session) {
484                 g_free(filename);
485                 return NULL;
486         }
487
488         ok = news_select_group(folder, item->path, NULL, NULL, NULL);
489         if (ok != NEWSNNTP_NO_ERROR) {
490                 if (ok == NEWSNNTP_ERROR_STREAM) {
491                         session_destroy(SESSION(session));
492                         REMOTE_FOLDER(folder)->session = NULL;
493                 }
494                 g_free(filename);
495                 return NULL;
496         }
497
498         debug_print("getting article %d...\n", num);
499         ok = news_get_article(folder,
500                               num, filename);
501         if (ok != NEWSNNTP_NO_ERROR) {
502                 g_warning("can't read article %d\n", num);
503                 if (ok == NEWSNNTP_ERROR_STREAM) {
504                         session_destroy(SESSION(session));
505                         REMOTE_FOLDER(folder)->session = NULL;
506                 }
507                 g_free(filename);
508                 return NULL;
509         }
510         GTK_EVENTS_FLUSH();
511         return filename;
512 }
513
514 static NewsGroupInfo *news_group_info_new(const gchar *name,
515                                           gint first, gint last, gchar type)
516 {
517         NewsGroupInfo *ginfo;
518
519         ginfo = g_new(NewsGroupInfo, 1);
520         ginfo->name = g_strdup(name);
521         ginfo->first = first;
522         ginfo->last = last;
523         ginfo->type = type;
524
525         return ginfo;
526 }
527
528 static void news_group_info_free(NewsGroupInfo *ginfo)
529 {
530         g_free(ginfo->name);
531         g_free(ginfo);
532 }
533
534 static gint news_group_info_compare(NewsGroupInfo *ginfo1,
535                                     NewsGroupInfo *ginfo2)
536 {
537         return g_ascii_strcasecmp(ginfo1->name, ginfo2->name);
538 }
539
540 GSList *news_get_group_list(Folder *folder)
541 {
542         gchar *path, *filename;
543         FILE *fp;
544         GSList *list = NULL;
545         GSList *last = NULL;
546         gchar buf[BUFFSIZE];
547
548         cm_return_val_if_fail(folder != NULL, NULL);
549         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
550
551         path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
552         if (!is_dir_exist(path))
553                 make_dir_hier(path);
554         filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
555         g_free(path);
556
557         if ((fp = g_fopen(filename, "rb")) == NULL) {
558                 NewsSession *session;
559                 gint ok;
560                 clist *grouplist = NULL;
561                 clistiter *cur;
562                 fp = g_fopen(filename, "wb");
563                 
564                 if (!fp) {
565                         g_free(filename);
566                         return NULL;
567                 }
568                 session = news_session_get(folder);
569                 if (!session) {
570                         fclose(fp);
571                         g_free(filename);
572                         return NULL;
573                 }
574
575                 ok = nntp_threaded_list(folder, &grouplist);
576                 
577                 if (ok != NEWSNNTP_NO_ERROR) {
578                         if (ok == NEWSNNTP_ERROR_STREAM) {
579                                 session_destroy(SESSION(session));
580                                 REMOTE_FOLDER(folder)->session = NULL;
581                         }
582                         fclose(fp);
583                         g_free(filename);
584                         return NULL;
585                 }
586                 
587                 if (grouplist) {
588                         for (cur = clist_begin(grouplist); cur; cur = clist_next(cur)) {
589                                 struct newsnntp_group_info *info = (struct newsnntp_group_info *)
590                                                                         clist_content(cur);
591                                 if (fprintf(fp, "%s %d %d %c\n",
592                                         info->grp_name,
593                                         info->grp_last,
594                                         info->grp_first,
595                                         info->grp_type) < 0) {
596                                         log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
597                                         session_destroy(SESSION(session));
598                                         REMOTE_FOLDER(folder)->session = NULL;
599                                         fclose(fp);
600                                         g_free(filename);
601                                         newsnntp_list_free(grouplist);
602                                         return NULL;
603                                 }
604                         }
605                         newsnntp_list_free(grouplist);
606                 }
607                 if (fclose(fp) == EOF) {
608                         log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
609                         session_destroy(SESSION(session));
610                         REMOTE_FOLDER(folder)->session = NULL;
611                         g_free(filename);
612                         return NULL;
613                 }
614
615                 if ((fp = g_fopen(filename, "rb")) == NULL) {
616                         FILE_OP_ERROR(filename, "fopen");
617                         g_free(filename);
618                         return NULL;
619                 }
620         }
621
622         while (fgets(buf, sizeof(buf), fp) != NULL) {
623                 gchar *p = buf;
624                 gchar *name;
625                 gint last_num;
626                 gint first_num;
627                 gchar type;
628                 NewsGroupInfo *ginfo;
629
630                 p = strchr(p, ' ');
631                 if (!p) continue;
632                 *p = '\0';
633                 p++;
634                 name = buf;
635
636                 if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
637                         continue;
638
639                 ginfo = news_group_info_new(name, first_num, last_num, type);
640
641                 if (!last)
642                         last = list = g_slist_append(NULL, ginfo);
643                 else {
644                         last = g_slist_append(last, ginfo);
645                         last = last->next;
646                 }
647         }
648
649         fclose(fp);
650         g_free(filename);
651
652         list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
653
654         return list;
655 }
656
657 void news_group_list_free(GSList *group_list)
658 {
659         GSList *cur;
660
661         if (!group_list) return;
662
663         for (cur = group_list; cur != NULL; cur = cur->next)
664                 news_group_info_free((NewsGroupInfo *)cur->data);
665         g_slist_free(group_list);
666 }
667
668 void news_remove_group_list_cache(Folder *folder)
669 {
670         gchar *path, *filename;
671
672         cm_return_if_fail(folder != NULL);
673         cm_return_if_fail(FOLDER_CLASS(folder) == &news_class);
674
675         path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
676         filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
677         g_free(path);
678
679         if (is_file_exist(filename)) {
680                 if (remove(filename) < 0)
681                         FILE_OP_ERROR(filename, "remove");
682         }
683         g_free(filename);
684 }
685
686 gint news_post(Folder *folder, const gchar *file)
687 {
688         gint ok;
689         char *contents = file_read_to_str_no_recode(file);
690         NewsSession *session;
691
692         cm_return_val_if_fail(folder != NULL, -1);
693         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
694         cm_return_val_if_fail(contents != NULL, -1);
695         
696         session = news_session_get(folder);
697         if (!session)  {
698                 g_free(contents);
699                 return -1;
700         }
701         
702         ok = nntp_threaded_post(folder, contents, strlen(contents));
703
704         if (ok != NEWSNNTP_NO_ERROR && ok != NEWSNNTP_ERROR_STREAM) {
705                 ok = nntp_threaded_mode_reader(folder);
706                 if (ok == NEWSNNTP_NO_ERROR)
707                         ok = nntp_threaded_post(folder, contents, strlen(contents));
708         }
709         g_free(contents);
710
711         if (ok == NEWSNNTP_ERROR_STREAM) {
712                 session_destroy(SESSION(session));
713                 REMOTE_FOLDER(folder)->session = NULL;
714         }
715
716         return (ok == NEWSNNTP_NO_ERROR ? 0 : -1);
717 }
718
719 static gint news_get_article(Folder *folder, gint num, gchar *filename)
720 {
721         size_t len;
722         char *result = NULL;
723         int r;
724         
725         r = nntp_threaded_article(folder, num, &result, &len);
726         
727         if (r == NEWSNNTP_NO_ERROR) {
728                 if (str_write_to_file(result, filename) < 0)
729                         return -1;
730                 g_free(result);
731         }
732         
733         return r;
734 }
735
736 /**
737  * news_select_group:
738  * @session: Active NNTP session.
739  * @group: Newsgroup name.
740  * @num: Estimated number of articles.
741  * @first: First article number.
742  * @last: Last article number.
743  *
744  * Select newsgroup @group with the GROUP command if it is not already
745  * selected in @session, or article numbers need to be returned.
746  *
747  * Return value: NNTP result code.
748  **/
749 static gint news_select_group(Folder *folder, const gchar *group,
750                               gint *num, gint *first, gint *last)
751 {
752         gint ok;
753         gint num_, first_, last_;
754         struct newsnntp_group_info *info = NULL;
755         NewsSession *session = NEWS_SESSION(news_session_get(folder));
756
757         cm_return_val_if_fail(session != NULL, -1);
758         
759         if (!num || !first || !last) {
760                 if (session->group && g_ascii_strcasecmp(session->group, group) == 0)
761                         return NEWSNNTP_NO_ERROR;
762                 num = &num_;
763                 first = &first_;
764                 last = &last_;
765         }
766
767         g_free(session->group);
768         session->group = NULL;
769
770         ok = nntp_threaded_group(folder, group, &info);
771         
772         if (ok != NEWSNNTP_NO_ERROR && 
773             ok != NEWSNNTP_ERROR_STREAM && 
774             ok != NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME) {
775                 ok = nntp_threaded_mode_reader(folder);
776                 if (ok == NEWSNNTP_NO_ERROR)
777                         ok = nntp_threaded_group(folder, group, &info);
778         }
779
780         if (ok == NEWSNNTP_NO_ERROR && info) {
781                 session->group = g_strdup(group);
782                 *num = info->grp_first;
783                 *first = info->grp_first;
784                 *last = info->grp_last;
785                 newsnntp_group_free(info);
786         } else {
787                 log_warning(LOG_PROTOCOL, _("couldn't select group: %s\n"), group);
788         }
789         return ok;
790 }
791
792 static MsgInfo *news_parse_xover(struct newsnntp_xover_resp_item *item)
793 {
794         MsgInfo *msginfo;
795
796         /* set MsgInfo */
797         msginfo = procmsg_msginfo_new();
798         msginfo->msgnum = item->ovr_article;
799         msginfo->size = item->ovr_size;
800
801         msginfo->date = g_strdup(item->ovr_date);
802         msginfo->date_t = procheader_date_parse(NULL, item->ovr_date, 0);
803
804         msginfo->from = conv_unmime_header(item->ovr_author, NULL, TRUE);
805         msginfo->fromname = procheader_get_fromname(msginfo->from);
806
807         msginfo->subject = conv_unmime_header(item->ovr_subject, NULL, TRUE);
808
809         remove_return(msginfo->from);
810         remove_return(msginfo->fromname);
811         remove_return(msginfo->subject);
812
813         if (item->ovr_message_id) {
814                 gchar *tmp = g_strdup(item->ovr_message_id);
815                 extract_parenthesis(tmp, '<', '>');
816                 remove_space(tmp);
817                 if (*tmp != '\0')
818                         msginfo->msgid = g_strdup(tmp);
819                 g_free(tmp);
820         }                        
821
822         /* FIXME: this is a quick fix; references' meaning was changed
823          * into having the actual list of references in the References: header.
824          * We need a GSList here, so msginfo_free() and msginfo_copy() can do 
825          * their things properly. */ 
826         if (item->ovr_references && *(item->ovr_references)) {   
827                 gchar **ref_tokens = g_strsplit(item->ovr_references, " ", -1);
828                 guint i = 0;
829                 char *tmp;
830                 char *p;
831                 while (ref_tokens[i]) {
832                         gchar *cur_ref = ref_tokens[i];
833                         msginfo->references = references_list_append(msginfo->references, 
834                                         cur_ref);
835                         i++;
836                 }
837                 g_strfreev(ref_tokens);
838                 
839                 tmp = g_strdup(item->ovr_references);
840                 eliminate_parenthesis(tmp, '(', ')');
841                 if ((p = strrchr(tmp, '<')) != NULL) {
842                         extract_parenthesis(p, '<', '>');
843                         remove_space(p);
844                         if (*p != '\0')
845                                 msginfo->inreplyto = g_strdup(p);
846                 }
847                 g_free(tmp);
848         } 
849
850         return msginfo;
851 }
852
853 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
854 {
855         gchar * tmp;
856         FILE * tmpfp;
857         gchar buf[BUFFSIZE];
858
859         tmp = g_strdup_printf("%s%ccancel%p", get_tmp_dir(),
860                               G_DIR_SEPARATOR, msginfo);
861         if (tmp == NULL)
862                 return -1;
863
864         if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
865                 FILE_OP_ERROR(tmp, "fopen");
866                 return -1;
867         }
868         if (change_file_mode_rw(tmpfp, tmp) < 0) {
869                 FILE_OP_ERROR(tmp, "chmod");
870                 g_warning("can't change file mode\n");
871         }
872         
873         get_rfc822_date(buf, sizeof(buf));
874         if (fprintf(tmpfp, "From: %s\r\n"
875                        "Newsgroups: %s\r\n"
876                        "Subject: cmsg cancel <%s>\r\n"
877                        "Control: cancel <%s>\r\n"
878                        "Approved: %s\r\n"
879                        "X-Cancelled-by: %s\r\n"
880                        "Date: %s\r\n"
881                        "\r\n"
882                        "removed with Claws Mail\r\n",
883                        msginfo->from,
884                        msginfo->newsgroups,
885                        msginfo->msgid,
886                        msginfo->msgid,
887                        msginfo->from,
888                        msginfo->from,
889                        buf) < 0) {
890                 FILE_OP_ERROR(tmp, "fprintf");
891                 fclose(tmpfp);
892                 claws_unlink(tmp);
893                 g_free(tmp);
894                 return -1;
895         }
896
897         if (fclose(tmpfp) == EOF) {
898                 FILE_OP_ERROR(tmp, "fclose");
899                 claws_unlink(tmp);
900                 g_free(tmp);
901                 return -1;
902         }
903
904         news_post(folder, tmp);
905         remove(tmp);
906
907         g_free(tmp);
908
909         return 0;
910 }
911
912 static gchar *news_folder_get_path(Folder *folder)
913 {
914         gchar *folder_path;
915
916         cm_return_val_if_fail(folder->account != NULL, NULL);
917
918         folder_path = g_strconcat(get_news_cache_dir(),
919                                   G_DIR_SEPARATOR_S,
920                                   folder->account->nntp_server,
921                                   NULL);
922         return folder_path;
923 }
924
925 static gchar *news_item_get_path(Folder *folder, FolderItem *item)
926 {
927         gchar *folder_path, *path;
928
929         cm_return_val_if_fail(folder != NULL, NULL);
930         cm_return_val_if_fail(item != NULL, NULL);
931         folder_path = news_folder_get_path(folder);
932
933         cm_return_val_if_fail(folder_path != NULL, NULL);
934         if (g_path_is_absolute(folder_path)) {
935                 if (item->path)
936                         path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
937                                            item->path, NULL);
938                 else
939                         path = g_strdup(folder_path);
940         } else {
941                 if (item->path)
942                         path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
943                                            folder_path, G_DIR_SEPARATOR_S,
944                                            item->path, NULL);
945                 else
946                         path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
947                                            folder_path, NULL);
948         }
949         g_free(folder_path);
950 #ifdef G_OS_WIN32
951         while (strchr(path, '/'))
952                 *strchr(path, '/') = '\\';
953 #endif
954         return path;
955 }
956
957 static gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list, gboolean *old_uids_valid)
958 {
959         NewsSession *session;
960         gint i, ok, num, first, last, nummsgs = 0;
961         gchar *dir;
962
963         cm_return_val_if_fail(item != NULL, -1);
964         cm_return_val_if_fail(item->folder != NULL, -1);
965         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
966
967         session = news_session_get(folder);
968         cm_return_val_if_fail(session != NULL, -1);
969
970         *old_uids_valid = TRUE;
971         
972         news_folder_lock(NEWS_FOLDER(item->folder));
973
974         ok = news_select_group(folder, item->path, &num, &first, &last);
975         if (ok != NEWSNNTP_NO_ERROR) {
976                 log_warning(LOG_PROTOCOL, _("couldn't set group: %s\n"), item->path);
977                 news_folder_unlock(NEWS_FOLDER(item->folder));
978                 return -1;
979         }
980
981         dir = news_folder_get_path(folder);
982         if (num <= 0)
983                 remove_all_numbered_files(dir);
984         else if (last < first)
985                 log_warning(LOG_PROTOCOL, _("invalid article range: %d - %d\n"),
986                             first, last);
987         else {
988                 for (i = first; i <= last; i++) {
989                         *msgnum_list = g_slist_prepend(*msgnum_list, 
990                                                        GINT_TO_POINTER(i));
991                         nummsgs++;
992                 }
993                 debug_print("removing old messages from %d to %d in %s\n",
994                             first, last, dir);
995                 remove_numbered_files(dir, 1, first - 1);
996         }
997         g_free(dir);
998         news_folder_unlock(NEWS_FOLDER(item->folder));
999         return nummsgs;
1000 }
1001
1002 static void news_set_msg_flags(FolderItem *item, MsgInfo *msginfo)
1003 {
1004         msginfo->flags.tmp_flags = 0;
1005         if (item->folder->account->mark_crosspost_read && msginfo->msgid) {
1006                 if (item->folder->newsart &&
1007                     g_hash_table_lookup(item->folder->newsart, msginfo->msgid) != NULL) {
1008                         msginfo->flags.perm_flags = MSG_COLORLABEL_TO_FLAGS(item->folder->account->crosspost_col);
1009                                 
1010                 } else {
1011                         if (!item->folder->newsart) 
1012                                 item->folder->newsart = g_hash_table_new(g_str_hash, g_str_equal);
1013                         g_hash_table_insert(item->folder->newsart,
1014                                         g_strdup(msginfo->msgid), GINT_TO_POINTER(1));
1015                         msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
1016                 }
1017         } else {
1018                 msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
1019         }
1020 }
1021
1022 static void news_get_extra_fields(NewsSession *session, FolderItem *item, GSList *msglist)
1023 {
1024         MsgInfo *msginfo = NULL;
1025         gint ok;
1026         GSList *cur;
1027         clist *hdrlist = NULL;
1028         clistiter *hdr;
1029         gint first = -1, last = -1;
1030         GHashTable *hash_table;
1031         
1032         cm_return_if_fail(session != NULL);
1033         cm_return_if_fail(item != NULL);
1034         cm_return_if_fail(item->folder != NULL);
1035         cm_return_if_fail(FOLDER_CLASS(item->folder) == &news_class);
1036
1037         news_folder_lock(NEWS_FOLDER(item->folder));
1038
1039         hash_table = g_hash_table_new(g_direct_hash, g_direct_equal);
1040         
1041         for (cur = msglist; cur; cur = cur->next) {
1042                 msginfo = (MsgInfo *)cur->data;
1043                 if (first == -1 || msginfo->msgnum < first)
1044                         first = msginfo->msgnum;
1045                 if (last == -1 || msginfo->msgnum > last)
1046                         last = msginfo->msgnum;
1047                 g_hash_table_insert(hash_table,
1048                                 GINT_TO_POINTER(msginfo->msgnum), msginfo);
1049         }
1050
1051 /* Newsgroups */
1052         ok = nntp_threaded_xhdr(item->folder, "newsgroups", first, last, &hdrlist);
1053
1054         if (ok != NEWSNNTP_NO_ERROR) {
1055                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1056                 if (ok == NEWSNNTP_ERROR_STREAM) {
1057                         session_destroy(SESSION(session));
1058                         REMOTE_FOLDER(item->folder)->session = NULL;
1059                 }
1060                 news_folder_unlock(NEWS_FOLDER(item->folder));
1061                 return;
1062         }
1063
1064         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1065                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1066                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1067                 if (msginfo) {
1068                         if (msginfo->newsgroups)
1069                                 g_free(msginfo->newsgroups);
1070                         msginfo->newsgroups = g_strdup(hdrval->hdr_value);
1071                 }
1072         }
1073         newsnntp_xhdr_free(hdrlist);
1074         
1075 /* To */
1076         ok = nntp_threaded_xhdr(item->folder, "to", first, last, &hdrlist);
1077
1078         if (ok != NEWSNNTP_NO_ERROR) {
1079                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1080                 if (ok == NEWSNNTP_ERROR_STREAM) {
1081                         session_destroy(SESSION(session));
1082                         REMOTE_FOLDER(item->folder)->session = NULL;
1083                 }
1084                 news_folder_unlock(NEWS_FOLDER(item->folder));
1085                 return;
1086         }
1087
1088         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1089                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1090                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1091                 if (msginfo) {
1092                         if (msginfo->to)
1093                                 g_free(msginfo->to);
1094                         msginfo->to = g_strdup(hdrval->hdr_value);
1095                 }
1096         }
1097         newsnntp_xhdr_free(hdrlist);
1098         
1099 /* Cc */
1100         ok = nntp_threaded_xhdr(item->folder, "cc", first, last, &hdrlist);
1101
1102         if (ok != NEWSNNTP_NO_ERROR) {
1103                 log_warning(LOG_PROTOCOL, _("couldn't get xhdr\n"));
1104                 if (ok == NEWSNNTP_ERROR_STREAM) {
1105                         session_destroy(SESSION(session));
1106                         REMOTE_FOLDER(item->folder)->session = NULL;
1107                 }
1108                 news_folder_unlock(NEWS_FOLDER(item->folder));
1109                 return;
1110         }
1111
1112         for (hdr = clist_begin(hdrlist); hdr; hdr = clist_next(hdr)) {
1113                 struct newsnntp_xhdr_resp_item *hdrval = clist_content(hdr);
1114                 msginfo = g_hash_table_lookup(hash_table, GINT_TO_POINTER(hdrval->hdr_article));
1115                 if (msginfo) {
1116                         if (msginfo->cc)
1117                                 g_free(msginfo->cc);
1118                         msginfo->cc = g_strdup(hdrval->hdr_value);
1119                 }
1120         }
1121         newsnntp_xhdr_free(hdrlist);
1122         
1123
1124         g_hash_table_destroy(hash_table);
1125         news_folder_unlock(NEWS_FOLDER(item->folder));
1126 }
1127
1128 static GSList *news_get_msginfos_for_range(NewsSession *session, FolderItem *item, guint begin, guint end)
1129 {
1130         GSList *newlist = NULL;
1131         GSList *llast = NULL;
1132         MsgInfo *msginfo;
1133         gint ok;
1134         clist *msglist = NULL;
1135         clistiter *cur;
1136         cm_return_val_if_fail(session != NULL, NULL);
1137         cm_return_val_if_fail(item != NULL, NULL);
1138
1139         log_message(LOG_PROTOCOL, _("getting xover %d - %d in %s...\n"),
1140                     begin, end, item->path);
1141
1142         news_folder_lock(NEWS_FOLDER(item->folder));
1143         
1144         ok = news_select_group(item->folder, item->path, NULL, NULL, NULL);
1145         if (ok != NEWSNNTP_NO_ERROR) {
1146                 log_warning(LOG_PROTOCOL, _("couldn't set group: %s\n"), item->path);
1147                 news_folder_unlock(NEWS_FOLDER(item->folder));
1148                 return NULL;
1149         }
1150
1151         ok = nntp_threaded_xover(item->folder, begin, end, NULL, &msglist);
1152         
1153         if (ok != NEWSNNTP_NO_ERROR) {
1154                 log_warning(LOG_PROTOCOL, _("couldn't get xover\n"));
1155                 if (ok == NEWSNNTP_ERROR_STREAM) {
1156                         session_destroy(SESSION(session));
1157                         REMOTE_FOLDER(item->folder)->session = NULL;
1158                 }
1159                 news_folder_unlock(NEWS_FOLDER(item->folder));
1160                 return NULL;
1161         }
1162
1163         if (msglist) {
1164                 for (cur = clist_begin(msglist); cur; cur = clist_next(cur)) {
1165                         struct newsnntp_xover_resp_item *ritem = (struct newsnntp_xover_resp_item *)clist_content(cur);
1166                         msginfo = news_parse_xover(ritem);
1167                         
1168                         if (!msginfo) {
1169                                 log_warning(LOG_PROTOCOL, _("invalid xover line\n"));
1170                                 continue;
1171                         }
1172
1173                         msginfo->folder = item;
1174                         news_set_msg_flags(item, msginfo);
1175                         msginfo->flags.tmp_flags |= MSG_NEWS;
1176
1177                         if (!newlist)
1178                                 llast = newlist = g_slist_append(newlist, msginfo);
1179                         else {
1180                                 llast = g_slist_append(llast, msginfo);
1181                                 llast = llast->next;
1182                         }
1183                 }
1184                 newsnntp_xover_resp_list_free(msglist);
1185         }
1186
1187         news_folder_unlock(NEWS_FOLDER(item->folder));
1188
1189         session_set_access_time(SESSION(session));
1190
1191         news_get_extra_fields(session, item, newlist);
1192         
1193         return newlist;
1194 }
1195
1196 static MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
1197 {
1198         GSList *msglist = NULL;
1199         NewsSession *session;
1200         MsgInfo *msginfo = NULL;
1201
1202         session = news_session_get(folder);
1203         cm_return_val_if_fail(session != NULL, NULL);
1204         cm_return_val_if_fail(item != NULL, NULL);
1205         cm_return_val_if_fail(item->folder != NULL, NULL);
1206         cm_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
1207
1208         msglist = news_get_msginfos_for_range(session, item, num, num);
1209  
1210         if (msglist)
1211                 msginfo = msglist->data;
1212         
1213         g_slist_free(msglist);
1214         
1215         return msginfo;
1216 }
1217
1218 static GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
1219 {
1220         NewsSession *session;
1221         GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
1222         guint first, last, next;
1223         guint tofetch, fetched;
1224         
1225         cm_return_val_if_fail(folder != NULL, NULL);
1226         cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
1227         cm_return_val_if_fail(msgnum_list != NULL, NULL);
1228         cm_return_val_if_fail(item != NULL, NULL);
1229         
1230         session = news_session_get(folder);
1231         cm_return_val_if_fail(session != NULL, NULL);
1232
1233         tmp_msgnum_list = g_slist_copy(msgnum_list);
1234         tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
1235
1236         progressindicator_start(PROGRESS_TYPE_NETWORK);
1237         tofetch = g_slist_length(tmp_msgnum_list);
1238         fetched = 0;
1239
1240         first = GPOINTER_TO_INT(tmp_msgnum_list->data);
1241         last = first;
1242         
1243         news_folder_lock(NEWS_FOLDER(item->folder));
1244         
1245         for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
1246                 next = GPOINTER_TO_INT(elem->data);
1247                 if(next != (last + 1)) {
1248 /*                      session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1249                         session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1250 */
1251                         tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1252                         msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1253                         fetched = last - first + 1;
1254                         first = next;
1255                 }
1256                 last = next;
1257         }
1258         
1259         news_folder_unlock(NEWS_FOLDER(item->folder));
1260         
1261 /*      session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
1262         session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
1263 */
1264         tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
1265         msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
1266
1267         g_slist_free(tmp_msgnum_list);
1268         
1269         progressindicator_stop(PROGRESS_TYPE_NETWORK);
1270
1271         return msginfo_list;
1272 }
1273
1274 static gboolean news_scan_required(Folder *folder, FolderItem *item)
1275 {
1276         return TRUE;
1277 }
1278
1279 void news_synchronise(FolderItem *item, gint days) 
1280 {
1281         news_gtk_synchronise(item, days);
1282 }
1283
1284 static gint news_rename_folder(Folder *folder, FolderItem *item,
1285                                 const gchar *name)
1286 {
1287         gchar *path;
1288          
1289         cm_return_val_if_fail(folder != NULL, -1);
1290         cm_return_val_if_fail(item != NULL, -1);
1291         cm_return_val_if_fail(item->path != NULL, -1);
1292         cm_return_val_if_fail(name != NULL, -1);
1293
1294         path = folder_item_get_path(item);
1295         if (!is_dir_exist(path))
1296                 make_dir_hier(path);
1297
1298         g_free(item->name);
1299         item->name = g_strdup(name);
1300
1301         return 0;
1302 }
1303
1304 static gint news_remove_folder(Folder *folder, FolderItem *item)
1305 {
1306         gchar *path;
1307
1308         cm_return_val_if_fail(folder != NULL, -1);
1309         cm_return_val_if_fail(item != NULL, -1);
1310         cm_return_val_if_fail(item->path != NULL, -1);
1311
1312         path = folder_item_get_path(item);
1313         if (remove_dir_recursive(path) < 0) {
1314                 g_warning("can't remove directory `%s'\n", path);
1315                 g_free(path);
1316                 return -1;
1317         }
1318
1319         g_free(path);
1320         folder_item_remove(item);
1321         return 0;
1322 }
1323
1324 #else
1325 #include <glib.h>
1326 #include <glib/gi18n.h>
1327 #include <gtk/gtk.h>
1328 #include "folder.h"
1329 #include "alertpanel.h"
1330
1331 static FolderClass news_class;
1332
1333 static void warn_etpan(void)
1334 {
1335         static gboolean missing_news_warning = TRUE;
1336         if (missing_news_warning) {
1337                 missing_news_warning = FALSE;
1338                 alertpanel_error(
1339                         _("You have one or more News accounts "
1340                           "defined. However this version of "
1341                           "Claws Mail has been built without "
1342                           "News support; your News account(s) are "
1343                           "disabled.\n\n"
1344                           "You probably need to "
1345                           "install libetpan and recompile "
1346                           "Claws Mail."));
1347         }
1348 }
1349 static Folder *news_folder_new(const gchar *name, const gchar *path)
1350 {
1351         warn_etpan();
1352         return NULL;
1353 }
1354 void news_group_list_free(GSList *group_list)
1355 {
1356         warn_etpan();
1357 }
1358 void news_remove_group_list_cache(Folder *folder)
1359 {
1360         warn_etpan();
1361 }
1362 int news_folder_locked(Folder *folder)
1363 {
1364         warn_etpan();
1365         return 0;
1366 }
1367 gint news_post(Folder *folder, const gchar *file)
1368 {
1369         warn_etpan();
1370         return -1;
1371 }
1372
1373 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
1374 {
1375         warn_etpan();
1376         return -1;
1377 }
1378
1379 GSList *news_get_group_list(Folder *folder)
1380 {
1381         warn_etpan();
1382         return NULL;
1383 }
1384
1385
1386 FolderClass *news_get_class(void)
1387 {
1388         if (news_class.idstr == NULL) {
1389                 news_class.type = F_NEWS;
1390                 news_class.idstr = "news";
1391                 news_class.uistr = "News";
1392
1393                 /* Folder functions */
1394                 news_class.new_folder = news_folder_new;
1395         };
1396
1397         return &news_class;
1398 }
1399
1400
1401 #endif