2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2006-01-13 18:24:38 +01:00
|
|
|
* Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
|
2001-04-19 14:21:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-09-21 20:22:51 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-07 08:47:27 +02:00
|
|
|
#include "defs.h"
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
2001-11-14 11:51:23 +01:00
|
|
|
#include <time.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#include "news.h"
|
2005-08-04 20:01:14 +02:00
|
|
|
#include "news_gtk.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "nntp.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "recv.h"
|
|
|
|
#include "procmsg.h"
|
|
|
|
#include "procheader.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "codeconv.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "prefs_common.h"
|
2001-04-26 18:41:29 +02:00
|
|
|
#include "prefs_account.h"
|
|
|
|
#include "inputdialog.h"
|
2002-12-02 18:41:39 +01:00
|
|
|
#include "log.h"
|
2003-03-03 21:45:57 +01:00
|
|
|
#include "progressindicator.h"
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "remotefolder.h"
|
|
|
|
#include "alertpanel.h"
|
2005-09-19 19:53:13 +02:00
|
|
|
#include "inc.h"
|
|
|
|
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2002-05-31 09:06:28 +02:00
|
|
|
# include "ssl.h"
|
|
|
|
#endif
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-06-06 15:05:23 +02:00
|
|
|
#define NNTP_PORT 119
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2002-05-31 09:06:28 +02:00
|
|
|
#define NNTPS_PORT 563
|
2002-03-25 10:37:38 +01:00
|
|
|
#endif
|
2001-06-06 15:05:23 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
typedef struct _NewsFolder NewsFolder;
|
2003-04-02 17:33:25 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
#define NEWS_FOLDER(obj) ((NewsFolder *)obj)
|
|
|
|
|
|
|
|
struct _NewsFolder
|
|
|
|
{
|
|
|
|
RemoteFolder rfolder;
|
|
|
|
|
|
|
|
gboolean use_auth;
|
2006-02-24 09:25:19 +01:00
|
|
|
gboolean lock_count;
|
2004-01-12 22:28:31 +01:00
|
|
|
};
|
2003-04-02 17:33:25 +02:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
static void news_folder_init (Folder *folder,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *path);
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static Folder *news_folder_new (const gchar *name,
|
|
|
|
const gchar *folder);
|
|
|
|
static void news_folder_destroy (Folder *folder);
|
|
|
|
|
|
|
|
static gchar *news_fetch_msg (Folder *folder,
|
|
|
|
FolderItem *item,
|
|
|
|
gint num);
|
|
|
|
|
|
|
|
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2002-03-25 10:37:38 +01:00
|
|
|
static Session *news_session_new (const gchar *server,
|
|
|
|
gushort port,
|
|
|
|
const gchar *userid,
|
2002-05-31 09:06:28 +02:00
|
|
|
const gchar *passwd,
|
|
|
|
SSLType ssl_type);
|
2002-03-25 10:37:38 +01:00
|
|
|
#else
|
2001-05-22 14:08:39 +02:00
|
|
|
static Session *news_session_new (const gchar *server,
|
|
|
|
gushort port,
|
|
|
|
const gchar *userid,
|
|
|
|
const gchar *passwd);
|
2002-03-25 10:37:38 +01:00
|
|
|
#endif
|
2001-05-22 14:08:39 +02:00
|
|
|
|
2001-04-30 14:52:29 +02:00
|
|
|
static gint news_get_article_cmd (NNTPSession *session,
|
2001-04-19 14:21:46 +02:00
|
|
|
const gchar *cmd,
|
|
|
|
gint num,
|
|
|
|
gchar *filename);
|
2001-04-30 14:52:29 +02:00
|
|
|
static gint news_get_article (NNTPSession *session,
|
2001-04-19 14:21:46 +02:00
|
|
|
gint num,
|
|
|
|
gchar *filename);
|
|
|
|
|
2001-05-03 20:11:22 +02:00
|
|
|
static gint news_select_group (NNTPSession *session,
|
2002-02-21 15:56:09 +01:00
|
|
|
const gchar *group,
|
|
|
|
gint *num,
|
|
|
|
gint *first,
|
|
|
|
gint *last);
|
2001-04-19 14:21:46 +02:00
|
|
|
static MsgInfo *news_parse_xover (const gchar *xover_str);
|
2001-05-22 14:08:39 +02:00
|
|
|
static gchar *news_parse_xhdr (const gchar *xhdr_str,
|
|
|
|
MsgInfo *msginfo);
|
2002-10-18 12:02:51 +02:00
|
|
|
gint news_get_num_list (Folder *folder,
|
|
|
|
FolderItem *item,
|
2003-08-21 22:08:27 +02:00
|
|
|
GSList **list,
|
|
|
|
gboolean *old_uids_valid);
|
2002-11-16 20:53:47 +01:00
|
|
|
MsgInfo *news_get_msginfo (Folder *folder,
|
2002-06-30 01:33:42 +02:00
|
|
|
FolderItem *item,
|
|
|
|
gint num);
|
2002-11-16 20:53:47 +01:00
|
|
|
GSList *news_get_msginfos (Folder *folder,
|
2002-06-30 01:33:42 +02:00
|
|
|
FolderItem *item,
|
|
|
|
GSList *msgnum_list);
|
2003-08-23 00:49:07 +02:00
|
|
|
gboolean news_scan_required (Folder *folder,
|
|
|
|
FolderItem *item);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-10-12 03:42:18 +02:00
|
|
|
gint news_post_stream (Folder *folder,
|
|
|
|
FILE *fp);
|
2003-07-03 22:37:07 +02:00
|
|
|
static gchar *news_folder_get_path (Folder *folder);
|
|
|
|
gchar *news_item_get_path (Folder *folder,
|
|
|
|
FolderItem *item);
|
2005-09-08 20:28:36 +02:00
|
|
|
static void news_synchronise (FolderItem *item);
|
2005-10-12 19:22:33 +02:00
|
|
|
static int news_dummy_remove (Folder *folder,
|
|
|
|
FolderItem *item,
|
|
|
|
gint msgnum);
|
2006-03-07 10:35:31 +01:00
|
|
|
static gint news_remove_folder (Folder *folder,
|
|
|
|
FolderItem *item);
|
2004-05-10 12:22:28 +02:00
|
|
|
static FolderClass news_class;
|
2003-03-12 16:40:51 +01:00
|
|
|
|
2003-05-13 13:54:19 +02:00
|
|
|
FolderClass *news_get_class(void)
|
2003-03-12 23:23:54 +01:00
|
|
|
{
|
2004-05-10 12:22:28 +02:00
|
|
|
if (news_class.idstr == NULL) {
|
|
|
|
news_class.type = F_NEWS;
|
|
|
|
news_class.idstr = "news";
|
|
|
|
news_class.uistr = "News";
|
|
|
|
|
|
|
|
/* Folder functions */
|
|
|
|
news_class.new_folder = news_folder_new;
|
|
|
|
news_class.destroy_folder = news_folder_destroy;
|
|
|
|
|
|
|
|
/* FolderItem functions */
|
|
|
|
news_class.item_get_path = news_item_get_path;
|
|
|
|
news_class.get_num_list = news_get_num_list;
|
|
|
|
news_class.scan_required = news_scan_required;
|
2006-03-07 10:35:31 +01:00
|
|
|
news_class.remove_folder = news_remove_folder;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
/* Message functions */
|
|
|
|
news_class.get_msginfo = news_get_msginfo;
|
|
|
|
news_class.get_msginfos = news_get_msginfos;
|
|
|
|
news_class.fetch_msg = news_fetch_msg;
|
2005-09-08 20:28:36 +02:00
|
|
|
news_class.synchronise = news_synchronise;
|
2005-10-12 19:22:33 +02:00
|
|
|
news_class.remove_msg = news_dummy_remove;
|
2004-05-10 12:22:28 +02:00
|
|
|
};
|
|
|
|
|
2003-03-12 23:23:54 +01:00
|
|
|
return &news_class;
|
|
|
|
}
|
|
|
|
|
2005-10-12 19:22:33 +02:00
|
|
|
static int news_dummy_remove (Folder *folder,
|
|
|
|
FolderItem *item,
|
|
|
|
gint msgnum)
|
|
|
|
{
|
|
|
|
debug_print("doing nothing on purpose\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
static void news_folder_lock(NewsFolder *folder)
|
|
|
|
{
|
|
|
|
folder->lock_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void news_folder_unlock(NewsFolder *folder)
|
|
|
|
{
|
|
|
|
if (folder->lock_count > 0)
|
|
|
|
folder->lock_count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int news_folder_locked(Folder *folder)
|
|
|
|
{
|
|
|
|
if (folder == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return NEWS_FOLDER(folder)->lock_count;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static Folder *news_folder_new(const gchar *name, const gchar *path)
|
2002-01-16 12:48:36 +01:00
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
folder = (Folder *)g_new0(NewsFolder, 1);
|
2003-04-05 22:38:53 +02:00
|
|
|
folder->klass = &news_class;
|
2002-01-16 12:48:36 +01:00
|
|
|
news_folder_init(folder, name, path);
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static void news_folder_destroy(Folder *folder)
|
2002-01-16 12:48:36 +01:00
|
|
|
{
|
2002-08-28 13:54:45 +02:00
|
|
|
gchar *dir;
|
|
|
|
|
2003-07-03 22:37:07 +02:00
|
|
|
dir = news_folder_get_path(folder);
|
2002-08-28 13:54:45 +02:00
|
|
|
if (is_dir_exist(dir))
|
|
|
|
remove_dir_recursive(dir);
|
|
|
|
g_free(dir);
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_remote_folder_destroy(REMOTE_FOLDER(folder));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void news_folder_init(Folder *folder, const gchar *name,
|
|
|
|
const gchar *path)
|
|
|
|
{
|
2002-07-25 23:09:10 +02:00
|
|
|
folder_remote_folder_init(folder, name, path);
|
2002-01-16 12:48:36 +01:00
|
|
|
}
|
|
|
|
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2002-03-25 10:37:38 +01:00
|
|
|
static Session *news_session_new(const gchar *server, gushort port,
|
2002-05-31 09:06:28 +02:00
|
|
|
const gchar *userid, const gchar *passwd,
|
|
|
|
SSLType ssl_type)
|
2002-03-25 10:37:38 +01:00
|
|
|
#else
|
2001-04-30 16:58:37 +02:00
|
|
|
static Session *news_session_new(const gchar *server, gushort port,
|
|
|
|
const gchar *userid, const gchar *passwd)
|
2002-03-25 10:37:38 +01:00
|
|
|
#endif
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gchar buf[NNTPBUFSIZE];
|
2003-03-27 14:26:07 +01:00
|
|
|
Session *session;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(server != NULL, NULL);
|
|
|
|
|
|
|
|
log_message(_("creating NNTP connection to %s:%d ...\n"), server, port);
|
|
|
|
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2003-03-27 14:26:07 +01:00
|
|
|
session = nntp_session_new(server, port, buf, userid, passwd, ssl_type);
|
2002-03-25 10:37:38 +01:00
|
|
|
#else
|
2003-03-27 14:26:07 +01:00
|
|
|
session = nntp_session_new(server, port, buf, userid, passwd);
|
2002-03-25 10:37:38 +01:00
|
|
|
#endif
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
return session;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-04-30 16:58:37 +02:00
|
|
|
static Session *news_session_new_for_folder(Folder *folder)
|
|
|
|
{
|
|
|
|
Session *session;
|
|
|
|
PrefsAccount *ac;
|
2001-05-22 14:08:39 +02:00
|
|
|
const gchar *userid = NULL;
|
|
|
|
gchar *passwd = NULL;
|
2002-05-31 09:06:28 +02:00
|
|
|
gushort port;
|
2003-01-27 11:33:19 +01:00
|
|
|
gchar buf[NNTPBUFSIZE];
|
2001-04-30 16:58:37 +02:00
|
|
|
|
2001-07-04 12:14:20 +02:00
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
g_return_val_if_fail(folder->account != NULL, NULL);
|
|
|
|
|
2001-04-30 16:58:37 +02:00
|
|
|
ac = folder->account;
|
2001-05-01 19:29:01 +02:00
|
|
|
if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
|
2001-04-30 16:58:37 +02:00
|
|
|
userid = ac->userid;
|
|
|
|
if (ac->passwd && ac->passwd[0])
|
|
|
|
passwd = g_strdup(ac->passwd);
|
2001-05-22 14:08:39 +02:00
|
|
|
else
|
2002-01-16 12:48:36 +01:00
|
|
|
passwd = input_dialog_query_password(ac->nntp_server,
|
|
|
|
userid);
|
2001-04-30 16:58:37 +02:00
|
|
|
}
|
2001-05-22 14:08:39 +02:00
|
|
|
|
2002-12-08 14:52:10 +01:00
|
|
|
#if USE_OPENSSL
|
2002-05-31 09:06:28 +02:00
|
|
|
port = ac->set_nntpport ? ac->nntpport
|
|
|
|
: ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT;
|
|
|
|
session = news_session_new(ac->nntp_server, port, userid, passwd,
|
|
|
|
ac->ssl_nntp);
|
2002-03-25 10:37:38 +01:00
|
|
|
#else
|
2005-09-19 19:53:13 +02:00
|
|
|
if (ac->ssl_nntp != SSL_NONE) {
|
|
|
|
if (alertpanel_full(_("Insecure connection"),
|
|
|
|
_("This connection is configured to be secured "
|
|
|
|
"using SSL, but SSL is not available in this "
|
|
|
|
"build of Sylpheed-Claws. \n\n"
|
|
|
|
"Do you want to continue connecting to this "
|
|
|
|
"server? The communication would not be "
|
|
|
|
"secure."),
|
2005-10-03 18:54:02 +02:00
|
|
|
_("Con_tinue connecting"),
|
2005-09-19 19:53:13 +02:00
|
|
|
GTK_STOCK_CANCEL, NULL,
|
|
|
|
FALSE, NULL, ALERT_WARNING,
|
|
|
|
G_ALERTALTERNATE) != G_ALERTDEFAULT)
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-05-31 09:06:28 +02:00
|
|
|
port = ac->set_nntpport ? ac->nntpport : NNTP_PORT;
|
|
|
|
session = news_session_new(ac->nntp_server, port, userid, passwd);
|
2002-03-25 10:37:38 +01:00
|
|
|
#endif
|
2003-02-24 17:51:59 +01:00
|
|
|
if ((session != NULL) && ac->use_nntp_auth && ac->use_nntp_auth_onconnect)
|
2003-03-27 14:26:07 +01:00
|
|
|
nntp_forceauth(NNTP_SESSION(session), buf, userid, passwd);
|
2002-05-31 09:06:28 +02:00
|
|
|
|
2001-04-30 16:58:37 +02:00
|
|
|
g_free(passwd);
|
2001-05-22 14:08:39 +02:00
|
|
|
|
2001-04-30 16:58:37 +02:00
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static NNTPSession *news_session_get(Folder *folder)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2001-11-16 11:44:43 +01:00
|
|
|
RemoteFolder *rfolder = REMOTE_FOLDER(folder);
|
2001-04-30 16:58:37 +02:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_val_if_fail(folder->account != NULL, NULL);
|
|
|
|
|
2006-03-01 19:09:06 +01:00
|
|
|
if (prefs_common.work_offline &&
|
|
|
|
!inc_offline_should_override(
|
|
|
|
_("Sylpheed-Claws needs network access in order "
|
|
|
|
"to access the News server."))) {
|
2004-01-12 22:28:31 +01:00
|
|
|
return NULL;
|
2005-08-04 20:01:14 +02:00
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
if (!rfolder->session) {
|
|
|
|
rfolder->session = news_session_new_for_folder(folder);
|
|
|
|
return NNTP_SESSION(rfolder->session);
|
2001-06-06 15:05:23 +02:00
|
|
|
}
|
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
if (time(NULL) - rfolder->session->last_access_time <
|
|
|
|
SESSION_TIMEOUT_INTERVAL) {
|
2001-11-16 11:44:43 +01:00
|
|
|
return NNTP_SESSION(rfolder->session);
|
2001-11-14 11:51:23 +01:00
|
|
|
}
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
if (nntp_mode(NNTP_SESSION(rfolder->session), FALSE)
|
2001-11-16 11:44:43 +01:00
|
|
|
!= NN_SUCCESS) {
|
2004-05-10 12:22:28 +02:00
|
|
|
log_warning(_("NNTP connection to %s:%d has been"
|
|
|
|
" disconnected. Reconnecting...\n"),
|
2001-07-04 12:14:20 +02:00
|
|
|
folder->account->nntp_server,
|
|
|
|
folder->account->set_nntpport ?
|
|
|
|
folder->account->nntpport : NNTP_PORT);
|
2001-11-16 11:44:43 +01:00
|
|
|
session_destroy(rfolder->session);
|
|
|
|
rfolder->session = news_session_new_for_folder(folder);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-11-18 13:23:39 +01:00
|
|
|
if (rfolder->session)
|
2004-08-06 13:34:34 +02:00
|
|
|
session_set_access_time(rfolder->session);
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
return NNTP_SESSION(rfolder->session);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
static gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gchar *path, *filename;
|
2001-07-15 15:42:30 +02:00
|
|
|
NNTPSession *session;
|
2001-04-19 14:21:46 +02:00
|
|
|
gint ok;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
2001-05-18 05:39:01 +02:00
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
2001-04-19 14:21:46 +02:00
|
|
|
filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
|
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
if (is_file_exist(filename)) {
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("article %d has been already cached.\n", num);
|
2001-04-19 14:21:46 +02:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2001-07-15 15:42:30 +02:00
|
|
|
session = news_session_get(folder);
|
|
|
|
if (!session) {
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-21 15:56:09 +01:00
|
|
|
ok = news_select_group(session, item->path, NULL, NULL, NULL);
|
2001-05-03 20:11:22 +02:00
|
|
|
if (ok != NN_SUCCESS) {
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
|
|
|
}
|
2001-05-03 20:11:22 +02:00
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("getting article %d...\n", num);
|
2001-04-30 14:52:29 +02:00
|
|
|
ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
|
2001-04-19 14:21:46 +02:00
|
|
|
num, filename);
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok != NN_SUCCESS) {
|
2002-12-10 19:42:29 +01:00
|
|
|
g_warning("can't read article %d\n", num);
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
GTK_EVENTS_FLUSH();
|
2001-04-19 14:21:46 +02:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
static NewsGroupInfo *news_group_info_new(const gchar *name,
|
|
|
|
gint first, gint last, gchar type)
|
2001-10-18 20:51:14 +02:00
|
|
|
{
|
2001-11-16 11:44:43 +01:00
|
|
|
NewsGroupInfo *ginfo;
|
2001-10-18 20:51:14 +02:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
ginfo = g_new(NewsGroupInfo, 1);
|
|
|
|
ginfo->name = g_strdup(name);
|
|
|
|
ginfo->first = first;
|
|
|
|
ginfo->last = last;
|
|
|
|
ginfo->type = type;
|
2001-10-18 20:51:14 +02:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
return ginfo;
|
2001-10-18 20:51:14 +02:00
|
|
|
}
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
static void news_group_info_free(NewsGroupInfo *ginfo)
|
2001-10-18 20:51:14 +02:00
|
|
|
{
|
2001-11-16 11:44:43 +01:00
|
|
|
g_free(ginfo->name);
|
|
|
|
g_free(ginfo);
|
2001-10-18 20:51:14 +02:00
|
|
|
}
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
static gint news_group_info_compare(NewsGroupInfo *ginfo1,
|
|
|
|
NewsGroupInfo *ginfo2)
|
2001-10-18 20:51:14 +02:00
|
|
|
{
|
2004-10-26 12:43:50 +02:00
|
|
|
return g_ascii_strcasecmp(ginfo1->name, ginfo2->name);
|
2001-10-18 20:51:14 +02:00
|
|
|
}
|
|
|
|
|
2001-07-15 15:42:30 +02:00
|
|
|
GSList *news_get_group_list(Folder *folder)
|
|
|
|
{
|
|
|
|
gchar *path, *filename;
|
|
|
|
FILE *fp;
|
|
|
|
GSList *list = NULL;
|
|
|
|
GSList *last = NULL;
|
|
|
|
gchar buf[NNTPBUFSIZE];
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
|
2001-07-15 15:42:30 +02:00
|
|
|
|
|
|
|
path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
|
2001-07-25 16:49:48 +02:00
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
2001-07-15 15:42:30 +02:00
|
|
|
filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
|
|
|
|
g_free(path);
|
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
if ((fp = g_fopen(filename, "rb")) == NULL) {
|
2001-11-16 11:44:43 +01:00
|
|
|
NNTPSession *session;
|
2004-05-10 12:22:28 +02:00
|
|
|
gint ok;
|
2001-07-15 15:42:30 +02:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
session = news_session_get(folder);
|
|
|
|
if (!session) {
|
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-15 15:42:30 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_list(session);
|
|
|
|
if (ok != NN_SUCCESS) {
|
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
|
|
|
}
|
2001-07-15 15:42:30 +02:00
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-03-27 14:26:07 +01:00
|
|
|
if (recv_write_to_file(SESSION(session)->sock, filename) < 0) {
|
2004-05-10 12:22:28 +02:00
|
|
|
log_warning(_("can't retrieve newsgroup list\n"));
|
2002-02-23 11:52:54 +01:00
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
2001-07-15 15:42:30 +02:00
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
if ((fp = g_fopen(filename, "rb")) == NULL) {
|
2001-07-15 15:42:30 +02:00
|
|
|
FILE_OP_ERROR(filename, "fopen");
|
|
|
|
g_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
2001-11-16 11:44:43 +01:00
|
|
|
gchar *p = buf;
|
|
|
|
gchar *name;
|
|
|
|
gint last_num;
|
|
|
|
gint first_num;
|
2001-10-18 20:51:14 +02:00
|
|
|
gchar type;
|
2001-11-16 11:44:43 +01:00
|
|
|
NewsGroupInfo *ginfo;
|
2001-10-18 20:51:14 +02:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
p = strchr(p, ' ');
|
|
|
|
if (!p) continue;
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
|
|
|
name = buf;
|
2001-10-18 20:51:14 +02:00
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
|
2001-10-18 20:51:14 +02:00
|
|
|
continue;
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
ginfo = news_group_info_new(name, first_num, last_num, type);
|
2001-10-18 20:51:14 +02:00
|
|
|
|
2001-07-15 15:42:30 +02:00
|
|
|
if (!last)
|
2001-11-16 11:44:43 +01:00
|
|
|
last = list = g_slist_append(NULL, ginfo);
|
2001-07-15 15:42:30 +02:00
|
|
|
else {
|
2001-11-16 11:44:43 +01:00
|
|
|
last = g_slist_append(last, ginfo);
|
2001-07-15 15:42:30 +02:00
|
|
|
last = last->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
g_free(filename);
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
|
2001-10-20 14:22:07 +02:00
|
|
|
|
2001-07-15 15:42:30 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2001-11-16 11:44:43 +01:00
|
|
|
void news_group_list_free(GSList *group_list)
|
|
|
|
{
|
|
|
|
GSList *cur;
|
|
|
|
|
|
|
|
if (!group_list) return;
|
|
|
|
|
|
|
|
for (cur = group_list; cur != NULL; cur = cur->next)
|
|
|
|
news_group_info_free((NewsGroupInfo *)cur->data);
|
|
|
|
g_slist_free(group_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void news_remove_group_list_cache(Folder *folder)
|
2001-07-15 15:42:30 +02:00
|
|
|
{
|
|
|
|
gchar *path, *filename;
|
|
|
|
|
|
|
|
g_return_if_fail(folder != NULL);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_if_fail(FOLDER_CLASS(folder) == &news_class);
|
2001-07-15 15:42:30 +02:00
|
|
|
|
|
|
|
path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
|
|
|
|
filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
|
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
if (is_file_exist(filename)) {
|
|
|
|
if (remove(filename) < 0)
|
|
|
|
FILE_OP_ERROR(filename, "remove");
|
|
|
|
}
|
|
|
|
g_free(filename);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gint news_post(Folder *folder, const gchar *file)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
gint ok;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, -1);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_val_if_fail(file != NULL, -1);
|
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
if ((fp = g_fopen(file, "rb")) == NULL) {
|
2001-04-19 14:21:46 +02:00
|
|
|
FILE_OP_ERROR(file, "fopen");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-10-04 17:35:49 +02:00
|
|
|
ok = news_post_stream(folder, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint news_post_stream(Folder *folder, FILE *fp)
|
|
|
|
{
|
|
|
|
NNTPSession *session;
|
|
|
|
gint ok;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, -1);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
|
2002-10-04 17:35:49 +02:00
|
|
|
g_return_val_if_fail(fp != NULL, -1);
|
|
|
|
|
|
|
|
session = news_session_get(folder);
|
|
|
|
if (!session) return -1;
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
ok = nntp_post(session, fp);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (ok != NN_SUCCESS) {
|
2004-05-10 12:22:28 +02:00
|
|
|
log_warning(_("can't post article.\n"));
|
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-30 14:52:29 +02:00
|
|
|
static gint news_get_article_cmd(NNTPSession *session, const gchar *cmd,
|
2001-04-19 14:21:46 +02:00
|
|
|
gint num, gchar *filename)
|
|
|
|
{
|
|
|
|
gchar *msgid;
|
2004-05-10 12:22:28 +02:00
|
|
|
gint ok;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_get_article(session, cmd, num, &msgid);
|
|
|
|
if (ok != NN_SUCCESS)
|
|
|
|
return ok;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-07-16 13:12:46 +02:00
|
|
|
debug_print("Message-ID = %s, num = %d\n", msgid, num);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(msgid);
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = recv_write_to_file(SESSION(session)->sock, filename);
|
|
|
|
if (ok < 0) {
|
|
|
|
log_warning(_("can't retrieve article %d\n"), num);
|
|
|
|
if (ok == -2)
|
|
|
|
return NN_SOCKET;
|
|
|
|
else
|
|
|
|
return NN_IOERR;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
return NN_SUCCESS;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-04-30 14:52:29 +02:00
|
|
|
static gint news_get_article(NNTPSession *session, gint num, gchar *filename)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2001-04-30 14:52:29 +02:00
|
|
|
return news_get_article_cmd(session, "ARTICLE", num, filename);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-05-03 20:11:22 +02:00
|
|
|
/**
|
|
|
|
* news_select_group:
|
|
|
|
* @session: Active NNTP session.
|
|
|
|
* @group: Newsgroup name.
|
2002-02-21 15:56:09 +01:00
|
|
|
* @num: Estimated number of articles.
|
|
|
|
* @first: First article number.
|
|
|
|
* @last: Last article number.
|
2001-05-22 14:08:39 +02:00
|
|
|
*
|
2001-05-03 20:11:22 +02:00
|
|
|
* Select newsgroup @group with the GROUP command if it is not already
|
2002-02-21 15:56:09 +01:00
|
|
|
* selected in @session, or article numbers need to be returned.
|
2001-05-22 14:08:39 +02:00
|
|
|
*
|
2001-05-03 20:11:22 +02:00
|
|
|
* Return value: NNTP result code.
|
|
|
|
**/
|
2002-02-21 15:56:09 +01:00
|
|
|
static gint news_select_group(NNTPSession *session, const gchar *group,
|
|
|
|
gint *num, gint *first, gint *last)
|
2001-05-03 20:11:22 +02:00
|
|
|
{
|
|
|
|
gint ok;
|
2002-02-21 15:56:09 +01:00
|
|
|
gint num_, first_, last_;
|
|
|
|
|
|
|
|
if (!num || !first || !last) {
|
2004-10-26 12:43:50 +02:00
|
|
|
if (session->group && g_ascii_strcasecmp(session->group, group) == 0)
|
2002-02-21 15:56:09 +01:00
|
|
|
return NN_SUCCESS;
|
|
|
|
num = &num_;
|
|
|
|
first = &first_;
|
|
|
|
last = &last_;
|
|
|
|
}
|
2001-05-03 20:11:22 +02:00
|
|
|
|
|
|
|
g_free(session->group);
|
|
|
|
session->group = NULL;
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
ok = nntp_group(session, group, num, first, last);
|
2001-05-03 20:11:22 +02:00
|
|
|
if (ok == NN_SUCCESS)
|
|
|
|
session->group = g_strdup(group);
|
2004-05-10 12:22:28 +02:00
|
|
|
else
|
|
|
|
log_warning(_("can't select group: %s\n"), group);
|
2001-05-03 20:11:22 +02:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
#define PARSE_ONE_PARAM(p, srcp) \
|
|
|
|
{ \
|
|
|
|
p = strchr(srcp, '\t'); \
|
|
|
|
if (!p) return NULL; \
|
|
|
|
else \
|
|
|
|
*p++ = '\0'; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static MsgInfo *news_parse_xover(const gchar *xover_str)
|
|
|
|
{
|
|
|
|
MsgInfo *msginfo;
|
2004-01-12 22:28:31 +01:00
|
|
|
gchar *subject, *sender, *size, *line, *date, *msgid, *ref, *tmp;
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar *p;
|
|
|
|
gint num, size_int, line_int;
|
|
|
|
gchar *xover_buf;
|
|
|
|
|
2001-11-07 11:29:45 +01:00
|
|
|
Xstrdup_a(xover_buf, xover_str, return NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
PARSE_ONE_PARAM(subject, xover_buf);
|
|
|
|
PARSE_ONE_PARAM(sender, subject);
|
|
|
|
PARSE_ONE_PARAM(date, sender);
|
|
|
|
PARSE_ONE_PARAM(msgid, date);
|
|
|
|
PARSE_ONE_PARAM(ref, msgid);
|
|
|
|
PARSE_ONE_PARAM(size, ref);
|
|
|
|
PARSE_ONE_PARAM(line, size);
|
2003-08-15 16:51:30 +02:00
|
|
|
/*
|
|
|
|
* PARSE_ONE_PARAM(xref, line);
|
|
|
|
*
|
|
|
|
* if we parse extra headers we should first examine the
|
|
|
|
* LIST OVERVIEW.FMT response from the server. See
|
|
|
|
* RFC2980 for details
|
|
|
|
*/
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-08-15 18:42:11 +02:00
|
|
|
tmp = strchr(line, '\t');
|
2001-04-19 14:21:46 +02:00
|
|
|
if (!tmp) tmp = strchr(line, '\r');
|
|
|
|
if (!tmp) tmp = strchr(line, '\n');
|
|
|
|
if (tmp) *tmp = '\0';
|
|
|
|
|
|
|
|
num = atoi(xover_str);
|
|
|
|
size_int = atoi(size);
|
|
|
|
line_int = atoi(line);
|
|
|
|
|
|
|
|
/* set MsgInfo */
|
2002-06-30 01:33:42 +02:00
|
|
|
msginfo = procmsg_msginfo_new();
|
2001-04-19 14:21:46 +02:00
|
|
|
msginfo->msgnum = num;
|
|
|
|
msginfo->size = size_int;
|
|
|
|
|
|
|
|
msginfo->date = g_strdup(date);
|
|
|
|
msginfo->date_t = procheader_date_parse(NULL, date, 0);
|
|
|
|
|
2005-03-18 08:56:55 +01:00
|
|
|
msginfo->from = conv_unmime_header(sender, NULL);
|
|
|
|
msginfo->fromname = procheader_get_fromname(msginfo->from);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-03-18 08:56:55 +01:00
|
|
|
msginfo->subject = conv_unmime_header(subject, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-03-30 22:29:56 +02:00
|
|
|
if (msgid) {
|
|
|
|
extract_parenthesis(msgid, '<', '>');
|
|
|
|
remove_space(msgid);
|
|
|
|
if (*msgid != '\0')
|
|
|
|
msginfo->msgid = g_strdup(msgid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: this is a quick fix; references' meaning was changed
|
|
|
|
* into having the actual list of references in the References: header.
|
|
|
|
* We need a GSList here, so msginfo_free() and msginfo_copy() can do
|
|
|
|
* their things properly. */
|
2005-03-31 17:31:13 +02:00
|
|
|
if (ref && strlen(ref)) {
|
|
|
|
gchar **ref_tokens = g_strsplit(ref, " ", -1);
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
while (ref_tokens[i]) {
|
|
|
|
gchar *cur_ref = ref_tokens[i];
|
|
|
|
msginfo->references = references_list_append(msginfo->references,
|
2005-12-13 18:32:23 +01:00
|
|
|
cur_ref);
|
2005-03-31 17:31:13 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
g_strfreev(ref_tokens);
|
|
|
|
|
2005-03-30 22:29:56 +02:00
|
|
|
eliminate_parenthesis(ref, '(', ')');
|
|
|
|
if ((p = strrchr(ref, '<')) != NULL) {
|
|
|
|
extract_parenthesis(p, '<', '>');
|
|
|
|
remove_space(p);
|
|
|
|
if (*p != '\0')
|
|
|
|
msginfo->inreplyto = g_strdup(p);
|
|
|
|
}
|
2005-03-31 17:31:13 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-08-15 18:42:11 +02:00
|
|
|
/*
|
2002-03-17 10:50:46 +01:00
|
|
|
msginfo->xref = g_strdup(xref);
|
|
|
|
p = msginfo->xref+strlen(msginfo->xref) - 1;
|
|
|
|
while (*p == '\r' || *p == '\n') {
|
|
|
|
*p = '\0';
|
|
|
|
p--;
|
|
|
|
}
|
2003-08-15 18:42:11 +02:00
|
|
|
*/
|
2002-03-17 10:50:46 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
2001-05-22 14:08:39 +02:00
|
|
|
static gchar *news_parse_xhdr(const gchar *xhdr_str, MsgInfo *msginfo)
|
2001-05-07 00:31:24 +02:00
|
|
|
{
|
|
|
|
gchar *p;
|
2001-05-22 14:08:39 +02:00
|
|
|
gchar *tmp;
|
2001-05-07 00:31:24 +02:00
|
|
|
gint num;
|
|
|
|
|
2001-05-22 14:08:39 +02:00
|
|
|
p = strchr(xhdr_str, ' ');
|
2001-05-07 00:31:24 +02:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
2001-05-22 14:08:39 +02:00
|
|
|
num = atoi(xhdr_str);
|
|
|
|
if (msginfo->msgnum != num) return NULL;
|
2001-05-07 00:31:24 +02:00
|
|
|
|
2001-05-09 16:24:02 +02:00
|
|
|
tmp = strchr(p, '\r');
|
|
|
|
if (!tmp) tmp = strchr(p, '\n');
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
return g_strndup(p, tmp - p);
|
|
|
|
else
|
|
|
|
return g_strdup(p);
|
2001-05-07 00:31:24 +02:00
|
|
|
}
|
|
|
|
|
2002-03-01 21:27:37 +01:00
|
|
|
gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
|
|
|
|
{
|
|
|
|
gchar * tmp;
|
|
|
|
FILE * tmpfp;
|
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
|
|
|
|
tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
|
|
|
|
G_DIR_SEPARATOR, (gint)msginfo);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
|
2002-03-01 21:27:37 +01:00
|
|
|
FILE_OP_ERROR(tmp, "fopen");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (change_file_mode_rw(tmpfp, tmp) < 0) {
|
|
|
|
FILE_OP_ERROR(tmp, "chmod");
|
2002-12-10 19:42:29 +01:00
|
|
|
g_warning("can't change file mode\n");
|
2002-03-01 21:27:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(tmpfp, "From: %s\r\n", msginfo->from);
|
|
|
|
fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
|
|
|
|
fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
|
|
|
|
fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
|
|
|
|
fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
|
|
|
|
fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
|
|
|
|
get_rfc822_date(buf, sizeof(buf));
|
|
|
|
fprintf(tmpfp, "Date: %s\r\n", buf);
|
|
|
|
fprintf(tmpfp, "\r\n");
|
|
|
|
fprintf(tmpfp, "removed with sylpheed\r\n");
|
|
|
|
|
|
|
|
fclose(tmpfp);
|
|
|
|
|
|
|
|
news_post(folder, tmp);
|
|
|
|
remove(tmp);
|
|
|
|
|
|
|
|
g_free(tmp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-07-03 22:37:07 +02:00
|
|
|
static gchar *news_folder_get_path(Folder *folder)
|
|
|
|
{
|
|
|
|
gchar *folder_path;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->account != NULL, NULL);
|
|
|
|
|
|
|
|
folder_path = g_strconcat(get_news_cache_dir(),
|
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
folder->account->nntp_server,
|
|
|
|
NULL);
|
|
|
|
return folder_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *news_item_get_path(Folder *folder, FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *folder_path, *path;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
folder_path = news_folder_get_path(folder);
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder_path != NULL, NULL);
|
|
|
|
if (folder_path[0] == G_DIR_SEPARATOR) {
|
|
|
|
if (item->path)
|
|
|
|
path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
|
|
|
|
item->path, NULL);
|
|
|
|
else
|
|
|
|
path = g_strdup(folder_path);
|
|
|
|
} else {
|
|
|
|
if (item->path)
|
|
|
|
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
folder_path, G_DIR_SEPARATOR_S,
|
|
|
|
item->path, NULL);
|
|
|
|
else
|
|
|
|
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
folder_path, NULL);
|
|
|
|
}
|
|
|
|
g_free(folder_path);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2003-08-21 22:08:27 +02:00
|
|
|
gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list, gboolean *old_uids_valid)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
NNTPSession *session;
|
2002-10-18 12:02:51 +02:00
|
|
|
gint i, ok, num, first, last, nummsgs = 0;
|
2002-10-05 15:02:50 +02:00
|
|
|
gchar *dir;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-10-18 12:02:51 +02:00
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
|
|
|
g_return_val_if_fail(item->folder != NULL, -1);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
|
2002-10-18 12:02:51 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
session = news_session_get(folder);
|
2002-10-18 12:02:51 +02:00
|
|
|
g_return_val_if_fail(session != NULL, -1);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-08-21 22:08:27 +02:00
|
|
|
*old_uids_valid = TRUE;
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
news_folder_lock(NEWS_FOLDER(item->folder));
|
2003-08-21 22:08:27 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
ok = news_select_group(session, item->path, &num, &first, &last);
|
|
|
|
if (ok != NN_SUCCESS) {
|
|
|
|
log_warning(_("can't set group: %s\n"), item->path);
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-10-18 12:02:51 +02:00
|
|
|
return -1;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
dir = news_folder_get_path(folder);
|
|
|
|
if (num <= 0)
|
2003-08-15 16:51:30 +02:00
|
|
|
remove_all_numbered_files(dir);
|
2004-02-21 12:01:01 +01:00
|
|
|
else if (last < first)
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("invalid article range: %d - %d\n"),
|
|
|
|
first, last);
|
2004-02-21 12:01:01 +01:00
|
|
|
else {
|
|
|
|
for (i = first; i <= last; i++) {
|
|
|
|
*msgnum_list = g_slist_prepend(*msgnum_list,
|
|
|
|
GINT_TO_POINTER(i));
|
|
|
|
nummsgs++;
|
|
|
|
}
|
|
|
|
debug_print("removing old messages from %d to %d in %s\n",
|
|
|
|
first, last, dir);
|
|
|
|
remove_numbered_files(dir, 1, first - 1);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-10-05 15:02:50 +02:00
|
|
|
g_free(dir);
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-10-18 12:02:51 +02:00
|
|
|
return nummsgs;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define READ_TO_LISTEND(hdr) \
|
|
|
|
while (!(buf[0] == '.' && buf[1] == '\r')) { \
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { \
|
2002-07-13 13:20:49 +02:00
|
|
|
log_warning(_("error occurred while getting %s.\n"), hdr); \
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2002-11-16 20:53:47 +01:00
|
|
|
MsgInfo *news_get_msginfo(Folder *folder, FolderItem *item, gint num)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
NNTPSession *session;
|
|
|
|
MsgInfo *msginfo = NULL;
|
|
|
|
gchar buf[NNTPBUFSIZE];
|
2004-05-10 12:22:28 +02:00
|
|
|
gint ok;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
session = news_session_get(folder);
|
|
|
|
g_return_val_if_fail(session != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item->folder != NULL, NULL);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(item->folder) == &news_class, NULL);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
log_message(_("getting xover %d in %s...\n"),
|
|
|
|
num, item->path);
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xover(session, num, num);
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
news_folder_lock(NEWS_FOLDER(item->folder));
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xover\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xover.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo = news_parse_xover(buf);
|
|
|
|
if (!msginfo) {
|
|
|
|
log_warning(_("invalid xover line: %s\n"), buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
READ_TO_LISTEND("xover");
|
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
if(!msginfo) {
|
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return NULL;
|
2006-02-24 09:25:19 +01:00
|
|
|
}
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
msginfo->folder = item;
|
|
|
|
msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
|
|
|
|
msginfo->flags.tmp_flags = MSG_NEWS;
|
|
|
|
msginfo->newsgroups = g_strdup(item->path);
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xhdr(session, "to", num, num);
|
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xhdr\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xhdr.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo->to = news_parse_xhdr(buf, msginfo);
|
|
|
|
|
|
|
|
READ_TO_LISTEND("xhdr (to)");
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xhdr(session, "cc", num, num);
|
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xhdr\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xhdr.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo->cc = news_parse_xhdr(buf, msginfo);
|
|
|
|
|
|
|
|
READ_TO_LISTEND("xhdr (cc)");
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
2002-11-16 20:53:47 +01:00
|
|
|
static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *item, guint begin, guint end)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
gchar buf[NNTPBUFSIZE];
|
|
|
|
GSList *newlist = NULL;
|
|
|
|
GSList *llast = NULL;
|
|
|
|
MsgInfo *msginfo;
|
2006-04-25 08:33:15 +02:00
|
|
|
guint count = 0, lines = (end - begin) + 2;
|
2004-05-10 12:22:28 +02:00
|
|
|
gint ok;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(session != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
log_message(_("getting xover %d - %d in %s...\n"),
|
|
|
|
begin, end, item->path);
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xover(session, begin, end);
|
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xover\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2003-02-13 20:05:55 +01:00
|
|
|
return NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_lock(NEWS_FOLDER(item->folder));
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
for (;;) {
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xover.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2003-02-13 20:05:55 +01:00
|
|
|
return newlist;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2003-03-03 21:45:57 +01:00
|
|
|
count++;
|
|
|
|
progressindicator_set_percentage
|
2003-03-03 22:49:30 +01:00
|
|
|
(PROGRESS_TYPE_NETWORK,
|
|
|
|
session->fetch_base_percentage +
|
|
|
|
(((gfloat) count) / ((gfloat) lines)) * session->fetch_total_percentage);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
if (buf[0] == '.' && buf[1] == '\r') break;
|
|
|
|
|
|
|
|
msginfo = news_parse_xover(buf);
|
|
|
|
if (!msginfo) {
|
|
|
|
log_warning(_("invalid xover line: %s\n"), buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo->folder = item;
|
|
|
|
msginfo->flags.perm_flags = MSG_NEW|MSG_UNREAD;
|
|
|
|
msginfo->flags.tmp_flags = MSG_NEWS;
|
|
|
|
msginfo->newsgroups = g_strdup(item->path);
|
|
|
|
|
|
|
|
if (!newlist)
|
|
|
|
llast = newlist = g_slist_append(newlist, msginfo);
|
|
|
|
else {
|
|
|
|
llast = g_slist_append(llast, msginfo);
|
|
|
|
llast = llast->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xhdr(session, "to", begin, end);
|
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xhdr\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2003-02-13 20:05:55 +01:00
|
|
|
return newlist;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
llast = newlist;
|
|
|
|
|
|
|
|
for (;;) {
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xhdr.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2003-02-13 20:05:55 +01:00
|
|
|
return newlist;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == '.' && buf[1] == '\r') break;
|
|
|
|
if (!llast) {
|
|
|
|
g_warning("llast == NULL\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo = (MsgInfo *)llast->data;
|
|
|
|
msginfo->to = news_parse_xhdr(buf, msginfo);
|
|
|
|
|
|
|
|
llast = llast->next;
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
ok = nntp_xhdr(session, "cc", begin, end);
|
|
|
|
if (ok != NN_SUCCESS) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("can't get xhdr\n"));
|
2004-05-10 12:22:28 +02:00
|
|
|
if (ok == NN_SOCKET) {
|
|
|
|
session_destroy(SESSION(session));
|
|
|
|
REMOTE_FOLDER(item->folder)->session = NULL;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2003-02-13 20:05:55 +01:00
|
|
|
return newlist;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
llast = newlist;
|
|
|
|
|
|
|
|
for (;;) {
|
2003-03-27 14:26:07 +01:00
|
|
|
if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
log_warning(_("error occurred while getting xhdr.\n"));
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2003-02-13 20:05:55 +01:00
|
|
|
return newlist;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[0] == '.' && buf[1] == '\r') break;
|
|
|
|
if (!llast) {
|
|
|
|
g_warning("llast == NULL\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
msginfo = (MsgInfo *)llast->data;
|
|
|
|
msginfo->cc = news_parse_xhdr(buf, msginfo);
|
|
|
|
|
|
|
|
llast = llast->next;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
session_set_access_time(SESSION(session));
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
return newlist;
|
|
|
|
}
|
|
|
|
|
2002-11-16 20:53:47 +01:00
|
|
|
GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
NNTPSession *session;
|
|
|
|
GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
|
|
|
|
guint first, last, next;
|
2003-03-03 21:45:57 +01:00
|
|
|
guint tofetch, fetched;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
2003-03-13 01:02:27 +01:00
|
|
|
g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
|
2002-06-30 01:33:42 +02:00
|
|
|
g_return_val_if_fail(msgnum_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
session = news_session_get(folder);
|
|
|
|
g_return_val_if_fail(session != NULL, NULL);
|
|
|
|
|
|
|
|
tmp_msgnum_list = g_slist_copy(msgnum_list);
|
2003-04-06 15:21:26 +02:00
|
|
|
tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, g_int_compare);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-03-03 21:45:57 +01:00
|
|
|
progressindicator_start(PROGRESS_TYPE_NETWORK);
|
|
|
|
tofetch = g_slist_length(tmp_msgnum_list);
|
|
|
|
fetched = 0;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
first = GPOINTER_TO_INT(tmp_msgnum_list->data);
|
|
|
|
last = first;
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
news_folder_lock(NEWS_FOLDER(item->folder));
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
|
|
|
|
next = GPOINTER_TO_INT(elem->data);
|
|
|
|
if(next != (last + 1)) {
|
2003-03-03 22:49:30 +01:00
|
|
|
session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
|
|
|
|
session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
|
2002-11-16 20:53:47 +01:00
|
|
|
tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
|
2002-06-30 01:33:42 +02:00
|
|
|
msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
|
2003-03-03 21:45:57 +01:00
|
|
|
fetched = last - first + 1;
|
2002-06-30 01:33:42 +02:00
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
last = next;
|
|
|
|
}
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
news_folder_unlock(NEWS_FOLDER(item->folder));
|
|
|
|
|
2003-03-03 22:49:30 +01:00
|
|
|
session->fetch_base_percentage = ((gfloat) fetched) / ((gfloat) tofetch);
|
|
|
|
session->fetch_total_percentage = ((gfloat) (last - first + 1)) / ((gfloat) tofetch);
|
2002-11-16 20:53:47 +01:00
|
|
|
tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
|
2002-06-30 01:33:42 +02:00
|
|
|
msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
|
|
|
|
|
|
|
|
g_slist_free(tmp_msgnum_list);
|
|
|
|
|
2003-03-03 21:45:57 +01:00
|
|
|
progressindicator_stop(PROGRESS_TYPE_NETWORK);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo_list;
|
|
|
|
}
|
2003-08-23 00:49:07 +02:00
|
|
|
|
|
|
|
gboolean news_scan_required(Folder *folder, FolderItem *item)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-09-08 20:28:36 +02:00
|
|
|
|
|
|
|
void news_synchronise(FolderItem *item)
|
|
|
|
{
|
|
|
|
news_gtk_synchronise(item);
|
|
|
|
}
|
2006-03-07 10:35:31 +01:00
|
|
|
|
|
|
|
static gint news_remove_folder(Folder *folder, FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, -1);
|
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
|
|
|
g_return_val_if_fail(item->path != NULL, -1);
|
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
|
|
|
if (remove_dir_recursive(path) < 0) {
|
|
|
|
g_warning("can't remove directory `%s'\n", path);
|
|
|
|
g_free(path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(path);
|
|
|
|
folder_item_remove(item);
|
|
|
|
return 0;
|
|
|
|
}
|