diff options
author | June McEnroe <june@causal.agency> | 2020-04-12 17:03:11 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-04-12 17:03:11 -0400 |
commit | 24e8b3ea43d2c9cdd130863133bf2266ebf27639 (patch) | |
tree | d2d9eb509cc781fd6e799bab3da871cae6b2bddd | |
parent | Factor out path functions (diff) | |
download | bubger-24e8b3ea43d2c9cdd130863133bf2266ebf27639.tar.gz bubger-24e8b3ea43d2c9cdd130863133bf2266ebf27639.zip |
Mangle message IDs in paths
/ is allowed in addr-spec but ; is not.
-rw-r--r-- | archive.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/archive.h b/archive.h index e9d4648..addd94d 100644 --- a/archive.h +++ b/archive.h @@ -19,6 +19,7 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include "imap.h" @@ -148,17 +149,27 @@ pathUID(char path[static PATH_MAX], uint32_t uid, const char *type) { return path; } +static inline const char *pathMangle(const char *messageID) { + if (!strchr(messageID, '/')) return messageID; + static char buf[PATH_MAX]; + strlcpy(buf, messageID, sizeof(buf)); + for (char *ptr = buf; (ptr = strchr(ptr, '/')); ++ptr) { + *ptr = ';'; + } + return buf; +} + static inline char *pathMessage( char path[static PATH_MAX], const char *messageID, const char *type ) { - snprintf(path, PATH_MAX, "message/%s.%s", messageID, type); + snprintf(path, PATH_MAX, "message/%s.%s", pathMangle(messageID), type); return path; } static inline char *pathThread( char path[static PATH_MAX], const char *messageID, const char *type ) { - snprintf(path, PATH_MAX, "thread/%s.%s", messageID, type); + snprintf(path, PATH_MAX, "thread/%s.%s", pathMangle(messageID), type); return path; } |