enriched.o enter.o filter.o flags.o from.o group.o handler.o \
hdrline.o help.o history.o hook.o init.o keymap.o \
main.o mbox.o menu.o mh.o muttlib.o mutt_account.o mutt_attach.o mutt_body.o mutt_header.o \
- mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o newsrc.o \
- nntp.o pager.o parse.o pattern.o \
+ mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o \
+ pager.o parse.o pattern.o \
postpone.o progress.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \
rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \
sendlib.o sidebar.o smtp.o sort.o state.o status.o system.o \
MUTTLIBS+= $(LIBPOP)
ALLOBJS+= $(LIBPOPOBJS)
+###############################################################################
+# libnntp
+LIBNNTP= libnntp.a
+LIBNNTPOBJS= nntp/newsrc.o nntp/nntp.o
+CLEANFILES+= $(LIBNNTP) $(LIBNNTPOBJS)
+MUTTLIBS+= $(LIBNNTP)
+ALLOBJS+= $(LIBNNTPOBJS)
+
###############################################################################
# libmutt
LIBMUTT= libmutt.a
$(PWD)/pop:
$(MKDIR_P) $(PWD)/pop
+# libnntp
+$(LIBNNTP): $(PWD)/nntp $(LIBNNTPOBJS)
+ $(AR) cr $@ $(LIBNNTPOBJS)
+ $(RANLIB) $@
+$(PWD)/nntp:
+ $(MKDIR_P) $(PWD)/nntp
+
# libncrypt
$(LIBNCRYPT): $(PWD)/ncrypt $(LIBNCRYPTOBJS)
$(AR) cr $@ $(LIBNCRYPTOBJS)
#include "imap/imap.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef USE_NOTMUCH
#include "mutt_notmuch.h"
#include "mailbox.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
/**
#include "remailer.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
static const char *There_are_no_attachments = N_("There are no attachments.");
#include "mutt_notmuch.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#include "imap/imap.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#define MUTT_IGNORE (1 << 0) /* -z */
#include "pop/pop.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef USE_NOTMUCH
#include "mutt_notmuch.h"
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
+#include "nntp_private.h"
#include "mutt/mutt.h"
#include "conn/conn.h"
#include "mutt.h"
#include <string.h>
#include <strings.h>
#include <unistd.h>
+#include "nntp_private.h"
#include "mutt/mutt.h"
#include "email/email.h"
#include "conn/conn.h"
#include "options.h"
#include "progress.h"
#include "protos.h"
+#include "sort.h"
#include "url.h"
#ifdef USE_HCACHE
#include "hcache/hcache.h"
return (rc < 0) ? -1 : 0;
}
+/**
+ * nntp_compare_order - Sort to mailbox order
+ * @param a First Header to compare
+ * @param b First Header to compare
+ * @retval -1 a precedes b
+ * @retval 0 a and b are identical
+ * @retval 1 b precedes a
+ */
+int nntp_compare_order(const void *a, const void *b)
+{
+ struct Header **ha = (struct Header **) a;
+ struct Header **hb = (struct Header **) b;
+
+ anum_t na = NHDR(*ha)->article_num;
+ anum_t nb = NHDR(*hb)->article_num;
+ int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
+ result = perform_auxsort(result, a, b);
+ return (SORTCODE(result));
+}
+
// clang-format off
/**
* struct mx_nntp_ops - Mailbox callback functions for NNTP mailboxes
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _MUTT_NNTP_H
-#define _MUTT_NNTP_H
+#ifndef _NNTP_NNTP_H
+#define _NNTP_NNTP_H
#include <stdbool.h>
#include <stdint.h>
struct Header;
struct Context;
-#define NNTP_PORT 119
-#define NNTP_SSL_PORT 563
-
-/* number of entries in article cache */
-#define NNTP_ACACHE_LEN 10
-
/* article number type and format */
#define anum_t uint32_t
#define ANUM "%u"
-/**
- * enum NntpStatus - NNTP server return values
- */
-enum NntpStatus
-{
- NNTP_NONE = 0,
- NNTP_OK,
- NNTP_BYE
-};
-
/**
* struct NntpServer - NNTP-specific server data
*/
struct NntpServer
{
- bool hasCAPABILITIES : 1;
- bool hasSTARTTLS : 1;
- bool hasDATE : 1;
+ bool hasCAPABILITIES : 1;
+ bool hasSTARTTLS : 1;
+ bool hasDATE : 1;
bool hasLIST_NEWSGROUPS : 1;
- bool hasXGTITLE : 1;
- bool hasLISTGROUP : 1;
- bool hasLISTGROUPrange : 1;
- bool hasOVER : 1;
- bool hasXOVER : 1;
- unsigned int use_tls : 3;
- unsigned int status : 3;
- bool cacheable : 1;
- bool newsrc_modified : 1;
+ bool hasXGTITLE : 1;
+ bool hasLISTGROUP : 1;
+ bool hasLISTGROUPrange : 1;
+ bool hasOVER : 1;
+ bool hasXOVER : 1;
+ unsigned int use_tls : 3;
+ unsigned int status : 3;
+ bool cacheable : 1;
+ bool newsrc_modified : 1;
FILE *newsrc_fp;
char *newsrc_file;
char *authenticators;
};
/**
- * struct NewsrcEntry - An entry in a .newsrc (subscribed newsgroups)
+ * struct NntpHeaderData - NNTP-specific header data
*/
-struct NewsrcEntry
+struct NntpHeaderData
{
- anum_t first;
- anum_t last;
+ anum_t article_num;
+ bool parsed : 1;
};
/**
char *path;
};
+/**
+ * struct NewsrcEntry - An entry in a .newsrc (subscribed newsgroups)
+ */
+struct NewsrcEntry
+{
+ anum_t first;
+ anum_t last;
+};
+
+/* number of entries in article cache */
+#define NNTP_ACACHE_LEN 10
+
/**
* struct NntpData - NNTP-specific server data
*/
anum_t last_cached;
anum_t unread;
bool subscribed : 1;
- bool new : 1;
- bool allowed : 1;
- bool deleted : 1;
+ bool new : 1;
+ bool allowed : 1;
+ bool deleted : 1;
unsigned int newsrc_len;
struct NewsrcEntry *newsrc_ent;
struct NntpServer *nserv;
struct BodyCache *bcache;
};
-/**
- * struct NntpHeaderData - NNTP-specific header data
- */
-struct NntpHeaderData
-{
- anum_t article_num;
- bool parsed : 1;
-};
-
-#define NHDR(hdr) ((struct NntpHeaderData *) ((hdr)->data))
-
-/* internal functions */
-int nntp_add_group(char *line, void *data);
-int nntp_active_save_cache(struct NntpServer *nserv);
-int nntp_check_new_groups(struct NntpServer *nserv);
-int nntp_open_connection(struct NntpServer *nserv);
-void nntp_newsrc_gen_entries(struct Context *ctx);
-void nntp_bcache_update(struct NntpData *nntp_data);
-void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum);
-void nntp_group_unread_stat(struct NntpData *nntp_data);
-void nntp_data_free(void *data);
-void nntp_acache_free(struct NntpData *nntp_data);
-void nntp_delete_group_cache(struct NntpData *nntp_data);
-
-/* exposed interface */
struct NntpServer *nntp_select_server(char *server, bool leave_lock);
struct NntpData *mutt_newsgroup_subscribe(struct NntpServer *nserv, char *group);
struct NntpData *mutt_newsgroup_unsubscribe(struct NntpServer *nserv, char *group);
const char *src, const char *prec, const char *if_str,
const char *else_str, unsigned long data, enum FormatFlag flags);
+void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum);
+
extern struct NntpServer *CurrentNewsSrv;
-#ifdef USE_HCACHE
-header_cache_t *nntp_hcache_open(struct NntpData *nntp_data);
-void nntp_hcache_update(struct NntpData *nntp_data, header_cache_t *hc);
-#endif
+int nntp_compare_order(const void *a, const void *b);
extern struct MxOps mx_nntp_ops;
-#endif /* _MUTT_NNTP_H */
+#endif /* _NNTP_NNTP_H */
--- /dev/null
+/**
+ * @file
+ * Usenet network mailbox type; talk to an NNTP server
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NNTP_PRIVATE_H
+#define _NNTP_PRIVATE_H
+
+#ifdef USE_HCACHE
+#include "hcache/hcache.h"
+#endif
+
+struct Context;
+struct Header;
+struct NntpData;
+struct NntpServer;
+
+#define NNTP_PORT 119
+#define NNTP_SSL_PORT 563
+
+/**
+ * enum NntpStatus - NNTP server return values
+ */
+enum NntpStatus
+{
+ NNTP_NONE = 0,
+ NNTP_OK,
+ NNTP_BYE
+};
+
+#define NHDR(hdr) ((struct NntpHeaderData *) ((hdr)->data))
+
+void nntp_acache_free(struct NntpData *nntp_data);
+int nntp_active_save_cache(struct NntpServer *nserv);
+int nntp_add_group(char *line, void *data);
+void nntp_bcache_update(struct NntpData *nntp_data);
+int nntp_check_new_groups(struct NntpServer *nserv);
+void nntp_data_free(void *data);
+void nntp_delete_group_cache(struct NntpData *nntp_data);
+void nntp_group_unread_stat(struct NntpData *nntp_data);
+void nntp_newsrc_gen_entries(struct Context *ctx);
+int nntp_open_connection(struct NntpServer *nserv);
+
+#ifdef USE_HCACHE
+header_cache_t *nntp_hcache_open(struct NntpData *nntp_data);
+void nntp_hcache_update(struct NntpData *nntp_data, header_cache_t *hc);
+#endif
+
+#endif /* _NNTP_PRIVATE_H */
#include "sidebar.h"
#endif
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
ncrypt/pgpmicalg.c
ncrypt/pgppacket.c
ncrypt/smime.c
-newsrc.c
-nntp.c
+nntp/newsrc.c
+nntp/nntp.c
opcodes.h
pager.c
parse.c
#include "url.h"
#ifdef USE_NNTP
#include "mx.h"
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef MIXMASTER
#include "remailer.h"
#include "rfc2231.h"
#include "state.h"
#ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
#ifdef HAVE_SYSEXITS_H
#include <sysexits.h>
#include "protos.h"
#ifdef USE_NNTP
#include "mx.h"
-#include "nntp.h"
+#include "nntp/nntp.h"
#endif
-#define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x
-
/* function to use as discriminator when normal sort method is equal */
static sort_t *AuxSort = NULL;
-static int perform_auxsort(int retval, const void *a, const void *b)
+int perform_auxsort(int retval, const void *a, const void *b)
{
/* If the items compared equal by the main sort
* and we're not already doing an 'aux' sort... */
struct Header **ha = (struct Header **) a;
struct Header **hb = (struct Header **) b;
-#ifdef USE_NNTP
- if (Context && Context->magic == MUTT_NNTP)
- {
- anum_t na = NHDR(*ha)->article_num;
- anum_t nb = NHDR(*hb)->article_num;
- int result = na == nb ? 0 : na > nb ? 1 : -1;
- result = perform_auxsort(result, a, b);
- return (SORTCODE(result));
- }
- else
-#endif
- /* no need to auxsort because you will never have equality here */
- return (SORTCODE((*ha)->index - (*hb)->index));
+ /* no need to auxsort because you will never have equality here */
+ return (SORTCODE((*ha)->index - (*hb)->index));
}
static int compare_spam(const void *a, const void *b)
case SORT_LABEL:
return compare_label;
case SORT_ORDER:
+#ifdef USE_NNTP
+ if (Context && (Context->magic == MUTT_NNTP))
+ return nntp_compare_order;
+ else
+#endif
return compare_order;
case SORT_RECEIVED:
return compare_date_received;
#define SORT_REVERSE (1 << 8)
#define SORT_LAST (1 << 9)
+#define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x
+
typedef int sort_t(const void *a, const void *b);
sort_t *mutt_get_sort_func(int method);
void mutt_sort_headers(struct Context *ctx, int init);
int mutt_select_sort(int reverse);
+int perform_auxsort(int retval, const void *a, const void *b);
extern const struct Mapping SortMethods[];