]> granicus.if.org Git - neomutt/commitdiff
Nntp: add Account
authorRichard Russon <rich@flatcap.org>
Sat, 20 Oct 2018 18:02:19 +0000 (19:02 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 25 Oct 2018 20:38:43 +0000 (21:38 +0100)
nntp/nntp.c

index c97776c5bbca4b88a92ab85797eee7ff413d0488..fa26fa3c55996be5f1a276553e5019d7b2698ef3 100644 (file)
@@ -6,6 +6,7 @@
  * Copyright (C) 1998 Brandon Long <blong@fiction.net>
  * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
  * Copyright (C) 2000-2017 Vsevolod Volkov <vvv@mutt.org.ua>
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
  *
  * @copyright
  * This program is free software: you can redistribute it and/or modify it under
@@ -41,6 +42,7 @@
 #include "conn/conn.h"
 #include "mutt.h"
 #include "nntp.h"
+#include "account.h"
 #include "bcache.h"
 #include "context.h"
 #include "curs_lib.h"
@@ -2276,6 +2278,54 @@ int nntp_compare_order(const void *a, const void *b)
   return SORTCODE(result);
 }
 
+/**
+ * nntp_ac_find - Find a Account that matches a Mailbox path
+ */
+struct Account *nntp_ac_find(struct Account *a, const char *path)
+{
+#if 0
+  if (!a || (a->type != MUTT_NNTP) || !path)
+    return NULL;
+
+  struct Url url;
+  char tmp[PATH_MAX];
+  mutt_str_strfcpy(tmp, path, sizeof(tmp));
+  url_parse(&url, tmp);
+
+  struct ImapAccountData *adata = a->data;
+  struct ConnAccount *ac = &adata->conn_account;
+
+  if (mutt_str_strcasecmp(url.host, ac->host) != 0)
+    return NULL;
+
+  if (mutt_str_strcasecmp(url.user, ac->user) != 0)
+    return NULL;
+
+  // if (mutt_str_strcmp(path, a->mailbox->realpath) == 0)
+  //   return a;
+#endif
+  return a;
+}
+
+/**
+ * nntp_ac_add - Add a Mailbox to a Account
+ */
+int nntp_ac_add(struct Account *a, struct Mailbox *m)
+{
+  if (!a || !m)
+    return -1;
+
+  if (m->magic != MUTT_NNTP)
+    return -1;
+
+  m->account = a;
+
+  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
+  np->m = m;
+  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
+  return 0;
+}
+
 /**
  * nntp_mbox_open - Implements MxOps::mbox_open()
  */
@@ -2312,6 +2362,11 @@ static int nntp_mbox_open(struct Context *ctx)
     return -1;
   CurrentNewsSrv = adata;
 
+  ctx->mailbox->account->adata = adata;
+
+  if (group[0] == '/')
+    group++;
+
   /* find news group data structure */
   mdata = mutt_hash_find(adata->groups_hash, group);
   if (!mdata)
@@ -2723,6 +2778,8 @@ int nntp_path_parent(char *buf, size_t buflen)
 struct MxOps mx_nntp_ops = {
   .magic            = MUTT_NNTP,
   .name             = "nntp",
+  .ac_find          = nntp_ac_find,
+  .ac_add           = nntp_ac_add,
   .mbox_open        = nntp_mbox_open,
   .mbox_open_append = NULL,
   .mbox_check       = nntp_mbox_check,