]> granicus.if.org Git - neomutt/commitdiff
move functions to mutt_address.c
authorRichard Russon <rich@flatcap.org>
Tue, 28 Nov 2017 15:01:16 +0000 (15:01 +0000)
committerRichard Russon <rich@flatcap.org>
Wed, 29 Nov 2017 00:29:09 +0000 (00:29 +0000)
Makefile.am
Makefile.autosetup
mutt_address.c [new file with mode: 0644]
po/POTFILES.in
rfc822.c
rfc822.h
sendlib.c

index 0a4376b8f12e3b2ecf15c84c5d15a5563796af24..3f313aa7cb0cc3d1271ea07db9a96d894a90e648 100644 (file)
@@ -49,7 +49,7 @@ neomutt_SOURCES = mutt_account.c addrbook.c address.h alias.c alias.h attach.c \
        envelope.c envelope.h filter.c flags.c format_flags.h from.c group.c \
        handler.c hdrline.c header.h header.c help.c history.c hook.c \
        init.c keymap.c main.c mbox.c mbyte.c mbtable.h \
-       menu.c mh.c muttlib.c mutt_idna.c mutt_socket.c \
+       menu.c mh.c muttlib.c mutt_address.c mutt_idna.c mutt_socket.c \
        mx.c newsrc.c nntp.c options.h pager.c parameter.c parameter.h \
        parse.c pattern.c pattern.h pop.c pop_auth.c pop_lib.c postpone.c \
        query.c recvattach.c recvcmd.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
index f54dbce13d126f96f76c00ce169299009e788bb6..bcb94c827da0718925ad41ae7a5d78ad1edb551f 100644 (file)
@@ -59,7 +59,7 @@ NEOMUTTOBJS=  mutt_account.o addrbook.o alias.o attach.o bcache.o body.o \
                curs_main.o edit.o editmsg.o enter.o envelope.o filter.o \
                flags.o from.o group.o handler.o hdrline.o \
                header.o help.o history.o hook.o init.o keymap.o main.o \
-               mbox.o mbyte.o menu.o mh.o muttlib.o mutt_idna.o \
+               mbox.o mbyte.o menu.o mh.o muttlib.o mutt_address.o mutt_idna.o \
                mutt_socket.o mutt_tags.o mx.o \
                newsrc.o nntp.o pager.o parameter.o parse.o pattern.o pop.o \
                pop_auth.o pop_lib.o postpone.o query.o recvattach.o recvcmd.o \
diff --git a/mutt_address.c b/mutt_address.c
new file mode 100644 (file)
index 0000000..8dcdecb
--- /dev/null
@@ -0,0 +1,204 @@
+/**
+ * @file
+ * Representation of an email address
+ *
+ * @authors
+ * Copyright (C) 1996-2000,2011-2013 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 2017 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/>.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+#include "mutt/mutt.h"
+#include "mutt_idna.h"
+#include "rfc822.h"
+
+void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display)
+{
+  size_t len;
+  char *pbuf = buf;
+  char *pc = NULL;
+
+  if (!addr)
+    return;
+
+  buflen--; /* save room for the terminal nul */
+
+  if (addr->personal)
+  {
+    if (strpbrk(addr->personal, RFC822Specials))
+    {
+      if (!buflen)
+        goto done;
+      *pbuf++ = '"';
+      buflen--;
+      for (pc = addr->personal; *pc && buflen > 0; pc++)
+      {
+        if (*pc == '"' || *pc == '\\')
+        {
+          *pbuf++ = '\\';
+          buflen--;
+        }
+        if (!buflen)
+          goto done;
+        *pbuf++ = *pc;
+        buflen--;
+      }
+      if (!buflen)
+        goto done;
+      *pbuf++ = '"';
+      buflen--;
+    }
+    else
+    {
+      if (!buflen)
+        goto done;
+      mutt_str_strfcpy(pbuf, addr->personal, buflen);
+      len = mutt_str_strlen(pbuf);
+      pbuf += len;
+      buflen -= len;
+    }
+
+    if (!buflen)
+      goto done;
+    *pbuf++ = ' ';
+    buflen--;
+  }
+
+  if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
+  {
+    if (!buflen)
+      goto done;
+    *pbuf++ = '<';
+    buflen--;
+  }
+
+  if (addr->mailbox)
+  {
+    if (!buflen)
+      goto done;
+    if ((mutt_str_strcmp(addr->mailbox, "@") != 0) && !display)
+    {
+      mutt_str_strfcpy(pbuf, addr->mailbox, buflen);
+      len = mutt_str_strlen(pbuf);
+    }
+    else if ((mutt_str_strcmp(addr->mailbox, "@") != 0) && display)
+    {
+      mutt_str_strfcpy(pbuf, mutt_addr_for_display(addr), buflen);
+      len = mutt_str_strlen(pbuf);
+    }
+    else
+    {
+      *pbuf = '\0';
+      len = 0;
+    }
+    pbuf += len;
+    buflen -= len;
+
+    if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
+    {
+      if (!buflen)
+        goto done;
+      *pbuf++ = '>';
+      buflen--;
+    }
+
+    if (addr->group)
+    {
+      if (!buflen)
+        goto done;
+      *pbuf++ = ':';
+      buflen--;
+      if (!buflen)
+        goto done;
+      *pbuf++ = ' ';
+      buflen--;
+    }
+  }
+  else
+  {
+    if (!buflen)
+      goto done;
+    *pbuf++ = ';';
+    buflen--;
+  }
+done:
+  /* no need to check for length here since we already save space at the
+     beginning of this routine */
+  *pbuf = 0;
+}
+
+/**
+ * rfc822_write_address - Write an address to a buffer
+ *
+ * Note: it is assumed that `buf' is nul terminated!
+ */
+int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display)
+{
+  char *pbuf = buf;
+  size_t len = mutt_str_strlen(buf);
+
+  buflen--; /* save room for the terminal nul */
+
+  if (len > 0)
+  {
+    if (len > buflen)
+      return pbuf - buf; /* safety check for bogus arguments */
+
+    pbuf += len;
+    buflen -= len;
+    if (!buflen)
+      goto done;
+    *pbuf++ = ',';
+    buflen--;
+    if (!buflen)
+      goto done;
+    *pbuf++ = ' ';
+    buflen--;
+  }
+
+  for (; addr && buflen > 0; addr = addr->next)
+  {
+    /* use buflen+1 here because we already saved space for the trailing
+       nul char, and the subroutine can make use of it */
+    rfc822_write_address_single(pbuf, buflen + 1, addr, display);
+
+    /* this should be safe since we always have at least 1 char passed into
+       the above call, which means `pbuf' should always be nul terminated */
+    len = mutt_str_strlen(pbuf);
+    pbuf += len;
+    buflen -= len;
+
+    /* if there is another address, and it's not a group mailbox name or
+       group terminator, add a comma to separate the addresses */
+    if (addr->next && addr->next->mailbox && !addr->group)
+    {
+      if (!buflen)
+        goto done;
+      *pbuf++ = ',';
+      buflen--;
+      if (!buflen)
+        goto done;
+      *pbuf++ = ' ';
+      buflen--;
+    }
+  }
+done:
+  *pbuf = 0;
+  return pbuf - buf;
+}
index 3d2a7d12d77eebe3e2533d8b8f71699a6499b15b..248167b3d523b1f48814b0badbbee09d55ce603f 100644 (file)
@@ -82,6 +82,7 @@ mutt/signal.c
 mutt/string.c
 muttlib.c
 mutt_account.c
+mutt_address.c
 mutt_idna.c
 mutt_lua.c
 mutt_notmuch.c
index 68797a812daf4cfb984dbe1a3bae222a3da97a2e..60378c9476c230f16401414f48ed04b797954acb 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -689,181 +689,6 @@ void rfc822_cat(char *buf, size_t buflen, const char *value, const char *special
     mutt_str_strfcpy(buf, value, buflen);
 }
 
-void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display)
-{
-  size_t len;
-  char *pbuf = buf;
-  char *pc = NULL;
-
-  if (!addr)
-    return;
-
-  buflen--; /* save room for the terminal nul */
-
-  if (addr->personal)
-  {
-    if (strpbrk(addr->personal, RFC822Specials))
-    {
-      if (!buflen)
-        goto done;
-      *pbuf++ = '"';
-      buflen--;
-      for (pc = addr->personal; *pc && buflen > 0; pc++)
-      {
-        if (*pc == '"' || *pc == '\\')
-        {
-          *pbuf++ = '\\';
-          buflen--;
-        }
-        if (!buflen)
-          goto done;
-        *pbuf++ = *pc;
-        buflen--;
-      }
-      if (!buflen)
-        goto done;
-      *pbuf++ = '"';
-      buflen--;
-    }
-    else
-    {
-      if (!buflen)
-        goto done;
-      mutt_str_strfcpy(pbuf, addr->personal, buflen);
-      len = mutt_str_strlen(pbuf);
-      pbuf += len;
-      buflen -= len;
-    }
-
-    if (!buflen)
-      goto done;
-    *pbuf++ = ' ';
-    buflen--;
-  }
-
-  if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
-  {
-    if (!buflen)
-      goto done;
-    *pbuf++ = '<';
-    buflen--;
-  }
-
-  if (addr->mailbox)
-  {
-    if (!buflen)
-      goto done;
-    if ((mutt_str_strcmp(addr->mailbox, "@") != 0) && !display)
-    {
-      mutt_str_strfcpy(pbuf, addr->mailbox, buflen);
-      len = mutt_str_strlen(pbuf);
-    }
-    else if ((mutt_str_strcmp(addr->mailbox, "@") != 0) && display)
-    {
-      mutt_str_strfcpy(pbuf, mutt_addr_for_display(addr), buflen);
-      len = mutt_str_strlen(pbuf);
-    }
-    else
-    {
-      *pbuf = '\0';
-      len = 0;
-    }
-    pbuf += len;
-    buflen -= len;
-
-    if (addr->personal || (addr->mailbox && *addr->mailbox == '@'))
-    {
-      if (!buflen)
-        goto done;
-      *pbuf++ = '>';
-      buflen--;
-    }
-
-    if (addr->group)
-    {
-      if (!buflen)
-        goto done;
-      *pbuf++ = ':';
-      buflen--;
-      if (!buflen)
-        goto done;
-      *pbuf++ = ' ';
-      buflen--;
-    }
-  }
-  else
-  {
-    if (!buflen)
-      goto done;
-    *pbuf++ = ';';
-    buflen--;
-  }
-done:
-  /* no need to check for length here since we already save space at the
-     beginning of this routine */
-  *pbuf = 0;
-}
-
-/**
- * rfc822_write_address - Write an address to a buffer
- *
- * Note: it is assumed that `buf' is nul terminated!
- */
-int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display)
-{
-  char *pbuf = buf;
-  size_t len = mutt_str_strlen(buf);
-
-  buflen--; /* save room for the terminal nul */
-
-  if (len > 0)
-  {
-    if (len > buflen)
-      return pbuf - buf; /* safety check for bogus arguments */
-
-    pbuf += len;
-    buflen -= len;
-    if (!buflen)
-      goto done;
-    *pbuf++ = ',';
-    buflen--;
-    if (!buflen)
-      goto done;
-    *pbuf++ = ' ';
-    buflen--;
-  }
-
-  for (; addr && buflen > 0; addr = addr->next)
-  {
-    /* use buflen+1 here because we already saved space for the trailing
-       nul char, and the subroutine can make use of it */
-    rfc822_write_address_single(pbuf, buflen + 1, addr, display);
-
-    /* this should be safe since we always have at least 1 char passed into
-       the above call, which means `pbuf' should always be nul terminated */
-    len = mutt_str_strlen(pbuf);
-    pbuf += len;
-    buflen -= len;
-
-    /* if there is another address, and it's not a group mailbox name or
-       group terminator, add a comma to separate the addresses */
-    if (addr->next && addr->next->mailbox && !addr->group)
-    {
-      if (!buflen)
-        goto done;
-      *pbuf++ = ',';
-      buflen--;
-      if (!buflen)
-        goto done;
-      *pbuf++ = ' ';
-      buflen--;
-    }
-  }
-done:
-  *pbuf = 0;
-  return pbuf - buf;
-}
-
 /**
  * rfc822_cpy_adr_real - Copy the real address
  * @param addr Address to copy
index d73bc04baad6744809026f673fe813cc2978e0c7..d983ab800a1f1e9cd50c18ffbfc4094aee744776 100644 (file)
--- a/rfc822.h
+++ b/rfc822.h
@@ -56,6 +56,7 @@ int rfc822_remove_from_adrlist(struct Address **a, const char *mailbox);
 
 extern int RFC822Error;
 extern const char *const RFC822Errors[];
+extern const char RFC822Specials[];
 
 #define rfc822_error(x) RFC822Errors[x]
 
index 073473dca66df30610204db018c85af5b7ccf6df..72e10db38b1aa4ddd544efc4b6eaa0073110c865 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -84,8 +84,6 @@
 #include <assert.h>
 #endif
 
-extern char RFC822Specials[];
-
 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
 
 static void encode_quoted(FGETCONV *fc, FILE *fout, int istext)