]> granicus.if.org Git - neomutt/commitdiff
Convert save-hook and fcc-hook to use buffer pool internally
authorKevin McCarthy <kevin@8t8.us>
Sun, 6 Oct 2019 08:32:42 +0000 (16:32 +0800)
committerRichard Russon <rich@flatcap.org>
Tue, 8 Oct 2019 16:43:58 +0000 (17:43 +0100)
The hook parameters still need to be converted, but I'm working
towards it slowly.

Co-authored-by: Richard Russon <rich@flatcap.org>
hook.c
muttlib.c
muttlib.h

diff --git a/hook.c b/hook.c
index 87f10d3b177f8ce9d8113f4859c6d7fdcda2613e..3cfcb6611fcaf65ccf9c346a12cdd360750f9d85 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -685,9 +685,10 @@ void mutt_default_save(char *path, size_t pathlen, struct Email *e)
     addr = NULL;
   if (addr)
   {
-    char tmp[PATH_MAX];
-    mutt_safe_path(tmp, sizeof(tmp), addr);
-    snprintf(path, pathlen, "=%s", tmp);
+    struct Buffer *tmp = mutt_buffer_pool_get();
+    mutt_safe_path(tmp, addr);
+    snprintf(path, pathlen, "=%s", mutt_b2s(tmp));
+    mutt_buffer_pool_release(&tmp);
   }
 }
 
@@ -707,9 +708,10 @@ void mutt_select_fcc(char *path, size_t pathlen, struct Email *e)
     if ((C_SaveName || C_ForceName) && (to || cc || bcc))
     {
       const struct Address *addr = to ? to : (cc ? cc : bcc);
-      char buf[PATH_MAX];
-      mutt_safe_path(buf, sizeof(buf), addr);
-      mutt_path_concat(path, NONULL(C_Folder), buf, pathlen);
+      struct Buffer *buf = mutt_buffer_pool_get();
+      mutt_safe_path(buf, addr);
+      mutt_path_concat(path, NONULL(C_Folder), mutt_b2s(buf), pathlen);
+      mutt_buffer_pool_release(&buf);
       if (!C_ForceName && (mx_access(path, W_OK) != 0))
         mutt_str_strfcpy(path, C_Record, pathlen);
     }
index e59caf7faa7964b50aba10f040d2c6a3ce3a77fb..e500aa0cefa227d573bc06d8958d0a2c7e3b0da1 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -810,18 +810,42 @@ void mutt_save_path(char *buf, size_t buflen, const struct Address *addr)
     *buf = '\0';
 }
 
+/**
+ * mutt_buffer_save_path - Make a safe filename from an email address
+ * @param dest Buffer for the result
+ * @param a    Address to use
+ */
+void mutt_buffer_save_path(struct Buffer *dest, const struct Address *a)
+{
+  if (a && a->mailbox)
+  {
+    mutt_buffer_strcpy(dest, a->mailbox);
+    if (!C_SaveAddress)
+    {
+      char *p = strpbrk(dest->data, "%@");
+      if (p)
+      {
+        *p = '\0';
+        mutt_buffer_fix_dptr(dest);
+      }
+    }
+    mutt_str_strlower(dest->data);
+  }
+  else
+    mutt_buffer_reset(dest);
+}
+
 /**
  * mutt_safe_path - Make a safe filename from an email address
- * @param buf    Buffer for the result
- * @param buflen Length of buffer
- * @param a Address to use
+ * @param dest Buffer for the result
+ * @param a    Address to use
  *
  * The filename will be stripped of '/', space, etc to make it safe.
  */
-void mutt_safe_path(char *buf, size_t buflen, const struct Address *a)
+void mutt_safe_path(struct Buffer *dest, const struct Address *a)
 {
-  mutt_save_path(buf, buflen, a);
-  for (char *p = buf; *p; p++)
+  mutt_buffer_save_path(dest, a);
+  for (char *p = dest->data; *p; p++)
     if ((*p == '/') || IS_SPACE(*p) || !IsPrint((unsigned char) *p))
       *p = '_';
 }
index 7bd151cdcef8e5488ea55250d8b35e7e311dbe5e..9628421dd517beb8f74d9b560a6baf66fc34d592 100644 (file)
--- a/muttlib.h
+++ b/muttlib.h
@@ -49,6 +49,7 @@ void        mutt_buffer_expand_path(struct Buffer *buf);
 void        mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex);
 void        mutt_buffer_pretty_mailbox(struct Buffer *s);
 void        mutt_buffer_sanitize_filename (struct Buffer *buf, const char *path, short slash);
+void        mutt_buffer_save_path(struct Buffer *dest, const struct Address *a);
 int         mutt_check_overwrite(const char *attname, const char *path, struct Buffer *fname, enum SaveAttach *opt, char **directory);
 void        mutt_encode_path(char *dest, size_t dlen, const char *src);
 void        mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags);
@@ -68,7 +69,7 @@ uint32_t    mutt_rand32(void);
 uint64_t    mutt_rand64(void);
 void        mutt_rand_base32(void *out, size_t len);
 int         mutt_randbuf(void *out, size_t len);
-void        mutt_safe_path(char *s, size_t l, const struct Address *a);
+void        mutt_safe_path(struct Buffer *dest, const struct Address *a);
 int         mutt_save_confirm(const char *s, struct stat *st);
 void        mutt_save_path(char *d, size_t dsize, const struct Address *a);
 void        mutt_sleep(short s);