CONTENT_STATE state;
FILE *fp = NULL;
char *fromcode = NULL;
- char *tocode;
+ char *tocode = NULL;
char buffer[100];
char chsbuf[STRING];
size_t r;
return p;
}
-static char mutt_normalized_char (char c)
+/* normalized character (we're stricter than RFC2822, 3.6.4) */
+static char mutt_normalized_char(char c)
{
- if (isalnum (c))
- return c;
- if (strchr (".!#$%&'*+-/=?^_`{|}~", c))
- return c;
- return '.'; /* normalized character (we're stricter than RFC2822, 3.6.4) */
+ return (isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.';
}
-static void mutt_gen_localpart(char *buf, unsigned int len, char *fmt)
+static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt)
{
+#define APPEND_FMT(fmt, arg) \
+ if (len > 1) { \
+ int snlen = snprintf(buf, len, fmt, arg); \
+ buf += snlen; \
+ len -= snlen; \
+ }
+
+#define APPEND_BYTE(c) \
+ if (len > 1) { \
+ *buf++ = c; \
+ *buf = '\0'; \
+ len--; \
+ }
+
time_t now;
struct tm *tm;
- int snlen;
-
- *buf = '\0';
now = time (NULL);
tm = gmtime (&now);
- for (; *fmt; ++fmt) {
-#define APPEND_FMT(fmt, ...) \
- if (len > 0) { \
- snlen = snprintf(buf, len, fmt, ##__VA_ARGS__); \
- buf += snlen; \
- len -= snlen; \
- }
+ while (*fmt) {
+ int c = *fmt++;
-#define APPEND_BYTE(c) \
- if (len > 1) { \
- *buf++ = c; \
- *buf = '\0'; \
- len--; \
+ if (c != '%') {
+ APPEND_BYTE(mutt_normalized_char(c));
+ continue;
}
- if (*fmt == '%') {
- switch (fmt[1]) {
- case 0:
- return;
- case 'd':
- APPEND_FMT("%02d", tm->tm_mday);
- break;
- case 'h':
- APPEND_FMT("%02d", tm->tm_hour);
- break;
- case 'm':
- APPEND_FMT("%02d", tm->tm_mon + 1);
- break;
- case 'M':
- APPEND_FMT("%02d", tm->tm_min);
- break;
- case 'O':
- APPEND_FMT("%lo", (unsigned long)now);
- break;
- case 'p':
- APPEND_FMT("%u", (unsigned int)getpid());
- break;
- case 'P':
- APPEND_FMT("%c", MsgIdPfx);
- MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1;
- break;
- case 'r':
- APPEND_FMT("%u", (unsigned int)rand());
- break;
- case 'R':
- APPEND_FMT("%x", (unsigned int)rand());
- break;
- case 's':
- APPEND_FMT("%02d", tm->tm_sec);
- break;
- case 'T':
- APPEND_FMT("%u", (unsigned int) now);
- break;
- case 'X':
- APPEND_FMT("%x", (unsigned int) now);
- break;
- case 'Y': /* this will break in the year 10000 ;-) */
- APPEND_FMT("%04d", tm->tm_year + 1900);
- break;
- case '%':
- APPEND_BYTE('%');
- break;
- default: /* invalid formats are replaced by '.' */
- APPEND_BYTE('.');
- m_strncat(buf, len, ".", 1);
- }
- ++fmt;
- } else {
- APPEND_BYTE(mutt_normalized_char(*fmt));
+ switch (*fmt++) {
+ case 0:
+ return;
+ case 'd':
+ APPEND_FMT("%02d", tm->tm_mday);
+ break;
+ case 'h':
+ APPEND_FMT("%02d", tm->tm_hour);
+ break;
+ case 'm':
+ APPEND_FMT("%02d", tm->tm_mon + 1);
+ break;
+ case 'M':
+ APPEND_FMT("%02d", tm->tm_min);
+ break;
+ case 'O':
+ APPEND_FMT("%lo", (unsigned long)now);
+ break;
+ case 'p':
+ APPEND_FMT("%u", (unsigned int)getpid());
+ break;
+ case 'P':
+ APPEND_FMT("%c", MsgIdPfx);
+ MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1;
+ break;
+ case 'r':
+ APPEND_FMT("%u", (unsigned int)rand());
+ break;
+ case 'R':
+ APPEND_FMT("%x", (unsigned int)rand());
+ break;
+ case 's':
+ APPEND_FMT("%02d", tm->tm_sec);
+ break;
+ case 'T':
+ APPEND_FMT("%u", (unsigned int) now);
+ break;
+ case 'X':
+ APPEND_FMT("%x", (unsigned int) now);
+ break;
+ case 'Y': /* this will break in the year 10000 ;-) */
+ APPEND_FMT("%04d", tm->tm_year + 1900);
+ break;
+ case '%':
+ APPEND_BYTE('%');
+ break;
+ default: /* invalid formats are replaced by '.' */
+ APPEND_BYTE('.');
+ m_strncat(buf, len, ".", 1);
}
+ }
+
+ *buf = '\0';
#undef APPEND_BYTE
#undef APPEND_FMT
- }
}
char *mutt_gen_msgid (void)