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