char *imap_get_qualifier(char *buf);
int imap_mxcmp(const char *mx1, const char *mx2);
char *imap_next_word(char *s);
-time_t imap_parse_date(char *s);
-void imap_make_date(char *buf, time_t timestamp);
void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path);
void imap_quote_string(char *dest, size_t slen, const char *src);
void imap_unquote_string(char *s);
void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src);
void imap_unmunge_mbox_name(struct ImapData *idata, char *s);
-int imap_wordcasecmp(const char *a, const char *b);
/* utf7.c */
void imap_utf_encode(struct ImapData *idata, char **s);
MUTT_PROGRESS_SIZE, NetInc, len);
imap_munge_mbox_name(idata, mbox, sizeof(mbox), mailbox);
- imap_make_date(internaldate, msg->received);
+ imap_make_date(internaldate, sizeof(internaldate), msg->received);
imap_flags[0] = imap_flags[1] = 0;
if (msg->flags.read)
return s;
}
-/**
- * imap_parse_date - Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
- */
-time_t imap_parse_date(char *s)
-{
- struct tm t;
- time_t tz;
-
- t.tm_mday = (s[0] == ' ' ? s[1] - '0' : (s[0] - '0') * 10 + (s[1] - '0'));
- s += 2;
- if (*s != '-')
- return 0;
- s++;
- t.tm_mon = mutt_check_month(s);
- s += 3;
- if (*s != '-')
- return 0;
- s++;
- t.tm_year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 +
- (s[3] - '0') - 1900;
- s += 4;
- if (*s != ' ')
- return 0;
- s++;
-
- /* time */
- t.tm_hour = (s[0] - '0') * 10 + (s[1] - '0');
- s += 2;
- if (*s != ':')
- return 0;
- s++;
- t.tm_min = (s[0] - '0') * 10 + (s[1] - '0');
- s += 2;
- if (*s != ':')
- return 0;
- s++;
- t.tm_sec = (s[0] - '0') * 10 + (s[1] - '0');
- s += 2;
- if (*s != ' ')
- return 0;
- s++;
-
- /* timezone */
- tz = ((s[1] - '0') * 10 + (s[2] - '0')) * 3600 + ((s[3] - '0') * 10 + (s[4] - '0')) * 60;
- if (s[0] == '+')
- tz = -tz;
-
- return (mutt_mktime(&t, 0) + tz);
-}
-
-/**
- * imap_make_date - format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
- *
- * Caller should provide a buffer of IMAP_DATELEN bytes
- */
-void imap_make_date(char *buf, time_t timestamp)
-{
- struct tm *tm = localtime(×tamp);
- time_t tz = mutt_local_tz(timestamp);
-
- tz /= 60;
-
- snprintf(buf, IMAP_DATELEN, "%02d-%s-%d %02d:%02d:%02d %+03d%02d",
- tm->tm_mday, Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
- tm->tm_min, tm->tm_sec, (int) tz / 60, (int) abs((int) tz) % 60);
-}
-
/**
* imap_qualify_path - Make an absolute IMAP folder target
*
FREE(&buf);
}
-/**
- * imap_wordcasecmp - find word a in word list b
- */
-int imap_wordcasecmp(const char *a, const char *b)
-{
- char tmp[SHORT_STRING];
- char *s = (char *) b;
- int i;
-
- tmp[SHORT_STRING - 1] = '\0';
- for (i = 0; i < SHORT_STRING - 2; i++, s++)
- {
- if (!*s || ISSPACE(*s))
- {
- tmp[i] = '\0';
- break;
- }
- tmp[i] = *s;
- }
- tmp[i + 1] = '\0';
-
- return mutt_strcasecmp(a, tmp);
-}
-
/*
* Imap keepalive: poll the current folder to keep the
* connection alive.
return 0;
}
-/**
- * rstrnstr - Find last instance of a substring
- *
- * Return the last instance of needle in the haystack, or NULL.
- * Like strstr(), only backwards, and for a limited haystack length.
- */
-static const char *rstrnstr(const char *haystack, size_t haystack_length, const char *needle)
-{
- int needle_length = strlen(needle);
- const char *haystack_end = haystack + haystack_length - needle_length;
- const char *p = NULL;
-
- for (p = haystack_end; p >= haystack; --p)
- {
- for (size_t i = 0; i < needle_length; ++i)
- {
- if (p[i] != needle[i])
- goto next;
- }
- return p;
-
- next:;
- }
- return NULL;
-}
-
/**
* mutt_nm_query_complete - Complete to the nearest notmuch tag
*
*
* | Function | Description
* | :-------------------- | :--------------------------------------------------
+ * | imap_make_date() | Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
+ * | imap_parse_date() | Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
* | is_day_name() | Is the string a valid day name
* | mutt_check_month() | Is the string a valid month name
* | mutt_local_tz() | Calculate the local timezone in seconds east of UTC
return (mutt_mktime(&tm, 0) + tz_offset);
}
+
+/**
+ * imap_make_date - Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
+ * @param buf Buffer to store the results
+ * @param buflen Length of buffer
+ * @param timestamp Time to format
+ * @retval int Number of characters written to buf
+ *
+ * Caller should provide a buffer of at least 27 bytes.
+ */
+int imap_make_date(char *buf, size_t buflen, time_t timestamp)
+{
+ struct tm *tm = localtime(×tamp);
+ time_t tz = mutt_local_tz(timestamp);
+
+ tz /= 60;
+
+ return snprintf(buf, buflen, "%02d-%s-%d %02d:%02d:%02d %+03d%02d",
+ tm->tm_mday, Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour,
+ tm->tm_min, tm->tm_sec, (int) tz / 60, (int) abs((int) tz) % 60);
+}
+
+/**
+ * imap_parse_date - Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
+ * @param str Date in string form
+ * @retval 0 Error
+ * @retval time_t Unix time
+ */
+time_t imap_parse_date(char *s)
+{
+ struct tm t;
+ time_t tz;
+
+ t.tm_mday = (s[0] == ' ' ? s[1] - '0' : (s[0] - '0') * 10 + (s[1] - '0'));
+ s += 2;
+ if (*s != '-')
+ return 0;
+ s++;
+ t.tm_mon = mutt_check_month(s);
+ s += 3;
+ if (*s != '-')
+ return 0;
+ s++;
+ t.tm_year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 +
+ (s[3] - '0') - 1900;
+ s += 4;
+ if (*s != ' ')
+ return 0;
+ s++;
+
+ /* time */
+ t.tm_hour = (s[0] - '0') * 10 + (s[1] - '0');
+ s += 2;
+ if (*s != ':')
+ return 0;
+ s++;
+ t.tm_min = (s[0] - '0') * 10 + (s[1] - '0');
+ s += 2;
+ if (*s != ':')
+ return 0;
+ s++;
+ t.tm_sec = (s[0] - '0') * 10 + (s[1] - '0');
+ s += 2;
+ if (*s != ' ')
+ return 0;
+ s++;
+
+ /* timezone */
+ tz = ((s[1] - '0') * 10 + (s[2] - '0')) * 3600 + ((s[3] - '0') * 10 + (s[4] - '0')) * 60;
+ if (s[0] == '+')
+ tz = -tz;
+
+ return (mutt_mktime(&t, 0) + tz);
+}
+
extern const char *const Months[];
extern const struct Tz TimeZones[];
-time_t mutt_local_tz(time_t t);
-time_t mutt_mktime(struct tm *t, int local);
-void mutt_normalize_time(struct tm *tm);
-char *mutt_make_date(char *buf, size_t buflen);
-time_t mutt_parse_date(const char *s, struct Tz *tz_out);
-bool is_day_name(const char *s);
-int mutt_check_month(const char *s);
+int imap_make_date(char *buf, size_t buflen, time_t timestamp);
+time_t imap_parse_date(char *s);
+bool is_day_name(const char *s);
+int mutt_check_month(const char *s);
+time_t mutt_local_tz(time_t t);
+char *mutt_make_date(char *buf, size_t buflen);
+time_t mutt_mktime(struct tm *t, int local);
+void mutt_normalize_time(struct tm *tm);
+time_t mutt_parse_date(const char *s, struct Tz *tz_out);
#endif /* _LIB_DATE_H */
*
* | Function | Description
* | :------------------------ | :---------------------------------------------------------
+ * | imap_wordcasecmp() | Find word a in word list b
* | is_email_wsp() | Is this a whitespace character (for an email header)
* | lwslen() | Measure the linear-white-space at the beginning of a string
* | lwsrlen() | Measure the linear-white-space at the end of a string
* | mutt_substrcpy() | Copy a sub-string into a buffer
* | mutt_substrdup() | Duplicate a sub-string
* | rfc822_dequote_comment() | Un-escape characters in an email address comment
+ * | rstrnstr() | Find last instance of a substring
* | safe_strcat() | Concatenate two strings
* | safe_strdup() | Copy a string, safely
* | safe_strncat() | Concatenate two strings
SKIPWS(s);
return s;
}
+
+/**
+ * rstrnstr - Find last instance of a substring
+ * @param haystack String to search through
+ * @param haystack_length Length of the string
+ * @param needle String to find
+ * @retval NULL String not found
+ * @retval ptr Location of string
+ *
+ * Return the last instance of needle in the haystack, or NULL.
+ * Like strstr(), only backwards, and for a limited haystack length.
+ */
+const char *rstrnstr(const char *haystack, size_t haystack_length, const char *needle)
+{
+ int needle_length = strlen(needle);
+ const char *haystack_end = haystack + haystack_length - needle_length;
+ const char *p = NULL;
+
+ for (p = haystack_end; p >= haystack; --p)
+ {
+ for (size_t i = 0; i < needle_length; ++i)
+ {
+ if (p[i] != needle[i])
+ goto next;
+ }
+ return p;
+
+ next:;
+ }
+ return NULL;
+}
+
+/**
+ * imap_wordcasecmp - Find word a in word list b
+ * @param a Word to find
+ * @param b String to check
+ * @retval 0 Word was found
+ * @retval !=0 Word was not found
+ *
+ * Given a word "apple", check if it exists at the start of a string of words,
+ * e.g. "apple banana". It must be an exact match, so "apple" won't match
+ * "apples banana".
+ *
+ * The case of the words is ignored.
+ */
+int imap_wordcasecmp(const char *a, const char *b)
+{
+ char tmp[SHORT_STRING] = "";
+
+ int i;
+ for (i = 0; i < SHORT_STRING - 2; i++, b++)
+ {
+ if (!*b || ISSPACE(*b))
+ {
+ tmp[i] = '\0';
+ break;
+ }
+ tmp[i] = *b;
+ }
+ tmp[i + 1] = '\0';
+
+ return mutt_strcasecmp(a, tmp);
+}
+
#define terminate_buffer(a, b) terminate_string(a, b, sizeof(a) - 1)
+int imap_wordcasecmp(const char *a, const char *b);
int is_email_wsp(char c);
size_t lwslen(const char *s, size_t n);
size_t lwsrlen(const char *s, size_t n);
char * mutt_substrdup(const char *begin, const char *end);
const char *next_word(const char *s);
void rfc822_dequote_comment(char *s);
+const char *rstrnstr(const char *haystack, size_t haystack_length, const char *needle);
char * safe_strcat(char *d, size_t l, const char *s);
char * safe_strdup(const char *s);
char * safe_strncat(char *d, size_t l, const char *s, size_t sl);