/* Ignore emails that appear to be more than a week in the future,
* since they can block all future updates during that time. */
- if (e->date_sent > (mutt_date_epoch_ms() / 1000 + (7 * 24 * 60 * 60)))
+ if (e->date_sent > (mutt_date_epoch() + (7 * 24 * 60 * 60)))
return 0;
for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
/* Ignore emails that appear to be more than a week in the future,
* since they can block all future updates during that time. */
- if (e->date_sent > (mutt_date_epoch_ms() / 1000 + (7 * 24 * 60 * 60)))
+ if (e->date_sent > (mutt_date_epoch() + (7 * 24 * 60 * 60)))
return 0;
struct Buffer *keyid = mutt_buffer_pool_get();
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <time.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "email/lib.h"
}
else
{
- time_t tnow = time(NULL);
- t_fmt = ((tnow - folder->ff->mtime) < 31536000) ? "%b %d %H:%M" : "%b %d %Y";
+ static const time_t one_year = 31536000;
+ t_fmt = ((mutt_date_epoch() - folder->ff->mtime) < one_year) ? "%b %d %H:%M" : "%b %d %Y";
}
if (!do_locales)
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
-#include <time.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "conn_globals.h"
* GNUTLS_CERT_EXPIRED and GNUTLS_CERT_NOT_ACTIVATED bits set. */
if (C_SslVerifyDates != MUTT_NO)
{
- if (gnutls_x509_crt_get_expiration_time(cert) < time(NULL))
+ if (gnutls_x509_crt_get_expiration_time(cert) < mutt_date_epoch())
*certerr |= CERTERR_EXPIRED;
- if (gnutls_x509_crt_get_activation_time(cert) > time(NULL))
+ if (gnutls_x509_crt_get_activation_time(cert) > mutt_date_epoch())
*certerr |= CERTERR_NOTYETVALID;
}
case 'e':
if ((mutt_str_strcasecmp("xpires", line + 1) == 0) && e &&
- (mutt_date_parse_date(p, NULL) < time(NULL)))
+ (mutt_date_parse_date(p, NULL) < mutt_date_epoch()))
{
e->expired = true;
}
mutt_copy_hdr(s->fp_in, s->fp_out, ftello(s->fp_in), b->parts->offset, chflags, NULL);
}
}
- else if (expiration && (expire < time(NULL)))
+ else if (expiration && (expire < mutt_date_epoch()))
{
if (s->flags & MUTT_DISPLAY)
{
if (optional && ((op == '[') || (op == '(')))
{
- now = time(NULL);
+ now = mutt_date_epoch();
struct tm tm = mutt_date_localtime(now);
now -= (op == '(') ? e->received : e->date_sent;
mutt_debug(LL_DEBUG3, "shrank buffer to %lu bytes\n", adata->blen);
}
- adata->lastread = time(NULL);
+ adata->lastread = mutt_date_epoch();
/* handle untagged messages. The caller still gets its shot afterwards. */
if ((mutt_str_startswith(adata->buf, "* ", CASE_MATCH) ||
/* try IDLE first, unless force is set */
if (!force && C_ImapIdle && (adata->capabilities & IMAP_CAP_IDLE) &&
- ((adata->state != IMAP_IDLE) || (time(NULL) >= adata->lastread + C_ImapKeepalive)))
+ ((adata->state != IMAP_IDLE) || (mutt_date_epoch() >= adata->lastread + C_ImapKeepalive)))
{
if (imap_cmd_idle(adata) < 0)
return -1;
}
}
- if ((force || ((adata->state != IMAP_IDLE) && (time(NULL) >= adata->lastread + C_Timeout))) &&
+ if ((force || ((adata->state != IMAP_IDLE) && (mutt_date_epoch() >= adata->lastread + C_Timeout))) &&
(imap_exec(adata, "NOOP", IMAP_CMD_POLL) != IMAP_EXEC_SUCCESS))
{
return -1;
*/
void imap_keepalive(void)
{
- time_t now = time(NULL);
+ time_t now = mutt_date_epoch();
struct Account *np = NULL;
TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
snprintf(AttachmentMarker, sizeof(AttachmentMarker), "\033]9;%" PRIu64 "\a", // Escape
mutt_rand64());
- snprintf(ProtectedHeaderMarker, sizeof(ProtectedHeaderMarker), "\033]8;%ld\a", // Escape
- (long) time(NULL));
+ snprintf(ProtectedHeaderMarker, sizeof(ProtectedHeaderMarker), "\033]8;%lld\a", // Escape
+ (long long) mutt_date_epoch());
/* "$spoolfile" precedence: config file, environment */
const char *p = mutt_str_getenv("MAIL");
while (true)
{
snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s",
- mailbox_path(m), subdir, (long long) time(NULL), mutt_rand64(),
- NONULL(ShortHostname), suffix);
+ mailbox_path(m), subdir, (long long) mutt_date_epoch(),
+ mutt_rand64(), NONULL(ShortHostname), suffix);
mutt_debug(LL_DEBUG2, "Trying %s\n", path);
struct Buffer *full = mutt_buffer_pool_get();
while (true)
{
- mutt_buffer_printf(path, "%s/%lld.R%" PRIu64 ".%s%s", subdir, (long long) time(NULL),
- mutt_rand64(), NONULL(ShortHostname), suffix);
+ mutt_buffer_printf(path, "%s/%lld.R%" PRIu64 ".%s%s", subdir,
+ (long long) mutt_date_epoch(), mutt_rand64(),
+ NONULL(ShortHostname), suffix);
mutt_buffer_printf(full, "%s/%s", mailbox_path(m), mutt_b2s(path));
mutt_debug(LL_DEBUG2, "renaming %s to %s\n", msg->path, mutt_b2s(full));
return 0;
if (t == 0)
- t = time(NULL);
+ t = mutt_date_epoch();
struct tm tm = mutt_date_gmtime(t);
return compute_tz(t, &tm);
if (!buf)
return NULL;
- time_t t = time(NULL);
+ time_t t = mutt_date_epoch();
struct tm tm = mutt_date_localtime(t);
time_t tz = mutt_date_local_tz(t);
return -1; /* error */
}
+/**
+ * mutt_date_epoch - Return the number of seconds since the Unix epoch
+ * @retval s The number of s since the Unix epoch, or 0 on failure
+ */
+time_t mutt_date_epoch(void)
+{
+ return mutt_date_epoch_ms() / 1000;
+}
+
/**
* mutt_date_epoch_ms - Return the number of milliseconds since the Unix epoch
* @retval ms The number of ms since the Unix epoch, or 0 on failure
struct tm tm = { 0 };
if (t == MUTT_DATE_NOW)
- t = time(NULL);
+ t = mutt_date_epoch();
localtime_r(&t, &tm);
return tm;
struct tm tm = { 0 };
if (t == MUTT_DATE_NOW)
- t = time(NULL);
+ t = mutt_date_epoch();
gmtime_r(&t, &tm);
return tm;
time_t mutt_date_add_timeout(time_t now, long timeout);
int mutt_date_check_month(const char *s);
+time_t mutt_date_epoch(void);
size_t mutt_date_epoch_ms(void);
struct tm mutt_date_gmtime(time_t t);
bool mutt_date_is_day_name(const char *s);
#include <unistd.h>
#include <utime.h>
#include "file.h"
+#include "date.h"
#include "buffer.h"
#include "logging.h"
#include "memory.h"
}
mtime = st->st_mtime;
- if (mtime == time(NULL))
+ if (mtime == mutt_date_epoch())
{
mtime -= 1;
utim.actime = mtime;
static time_t last = 0;
if (stamp == 0)
- stamp = time(NULL);
+ stamp = mutt_date_epoch();
if (stamp != last)
{
}
struct LogLine *ll = mutt_mem_calloc(1, sizeof(*ll));
- ll->time = (stamp != 0) ? stamp : time(NULL);
+ ll->time = (stamp != 0) ? stamp : mutt_date_epoch();
ll->file = file;
ll->line = line;
ll->function = function;
if (TAILQ_EMPTY(&NeoMutt->accounts))
return 0;
- t = time(NULL);
+ t = mutt_date_epoch();
if (!force && (t - MailboxTime < C_MailCheck))
return MailboxCount;
#if HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &m->last_visited);
#else
+ m->last_visited.tv_sec = mutt_date_epoch();
m->last_visited.tv_nsec = 0;
- time(&m->last_visited.tv_sec);
#endif
}
utimensat(0, buf, ts, 0);
#else
ut.actime = st->st_atime;
- ut.modtime = time(NULL);
+ ut.modtime = mutt_date_epoch();
utime(path, &ut);
#endif
}
}
if (msg->received == 0)
- time(&msg->received);
+ msg->received = mutt_date_epoch();
if (m->mx_ops->msg_open_new(m, msg, e) == 0)
{
*/
bool pgp_class_valid_passphrase(void)
{
- time_t now = time(NULL);
-
if (pgp_use_gpg_agent())
{
*PgpPass = '\0';
return true; /* handled by gpg-agent */
}
- if (now < PgpExptime)
+ if (mutt_date_epoch() < PgpExptime)
{
/* Use cached copy. */
return true;
if (mutt_get_password(_("Enter PGP passphrase:"), PgpPass, sizeof(PgpPass)) == 0)
{
- PgpExptime = mutt_date_add_timeout(time(NULL), C_PgpTimeout);
+ PgpExptime = mutt_date_add_timeout(mutt_date_epoch(), C_PgpTimeout);
return true;
}
else
*/
bool smime_class_valid_passphrase(void)
{
- time_t now = time(NULL);
-
+ const time_t now = mutt_date_epoch();
if (now < SmimeExptime)
{
/* Use cached copy. */
if (mutt_get_password(_("Enter S/MIME passphrase:"), SmimePass, sizeof(SmimePass)) == 0)
{
- SmimeExptime = mutt_date_add_timeout(time(NULL), C_SmimeTimeout);
+ SmimeExptime = mutt_date_add_timeout(now, C_SmimeTimeout);
return true;
}
else
struct NntpMboxData *mdata = m->mdata;
struct NntpAccountData *adata = mdata->adata;
- time_t now = time(NULL);
+ time_t now = mutt_date_epoch();
int rc = 0;
void *hc = NULL;
}
}
}
- time(now);
+ *now = mutt_date_epoch();
return 0;
}
}
}
- time(&adata->check_time);
+ adata->check_time = mutt_date_epoch();
m->mdata = mdata;
// Every known newsgroup has an mdata which is stored in adata->groups_list.
// Currently we don't let the Mailbox free the mdata.
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <time.h>
#include <unistd.h>
#include "notmuch_private.h"
#include "mutt/mutt.h"
notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
read_threads_query(m, q, true, 0);
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
rc = 0;
int rc = rename_filename(m, old_file, new_file, e);
nm_db_release(m);
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
return rc;
}
nm_db_release(m);
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
mdata->oldmsgcount = 0;
nm_db_release(m);
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
mutt_debug(LL_DEBUG1, "nm: ... check done [count=%d, new_flags=%d, occult=%d]\n",
if (changed)
{
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
}
nm_db_release(m);
if (e->changed)
{
- m->mtime.tv_sec = time(NULL);
+ m->mtime.tv_sec = mutt_date_epoch();
m->mtime.tv_nsec = 0;
}
mutt_debug(LL_DEBUG1, "nm: tags modify done [rc=%d]\n", rc);
header_cache_t *hc = pop_hcache_open(adata, mailbox_path(m));
#endif
- time(&adata->check_time);
+ adata->check_time = mutt_date_epoch();
adata->clear_cache = false;
if (!m->emails)
struct PopAccountData *adata = pop_adata_get(m);
- if ((adata->check_time + C_PopCheckinterval) > time(NULL))
+ if ((adata->check_time + C_PopCheckinterval) > mutt_date_epoch())
return 0;
pop_logout(m);
return (C_TimeInc == 0) || (now < progress->timestamp) || (C_TimeInc < elapsed);
}
-/**
- * progress_timestamp - Return the number of milliseconds since the Unix epoch
- * @retval ms Milliseconds since the Unix epoch
- */
-static size_t progress_timestamp(void)
-{
- struct timeval tv = { 0, 0 };
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
-
/**
* mutt_progress_init - Set up a progress bar
* @param progress Progress bar
if (OptNoCurses)
return;
- const size_t now = progress_timestamp();
+ const size_t now = mutt_date_epoch_ms();
const bool update = (pos == 0) /* always show the first update */ ||
(progress_pos_needs_update(progress, pos) &&
/* update received time so that when storing to a mbox-style folder
* the From_ line contains the current time instead of when the
* message was first postponed. */
- e->received = time(NULL);
+ e->received = mutt_date_epoch();
rc = mutt_write_multiple_fcc(fcc, e, NULL, false, NULL, finalpath);
while (rc && !(flags & SEND_BATCH))
{
*/
void mutt_stamp_attachment(struct Body *a)
{
- a->stamp = time(NULL);
+ a->stamp = mutt_date_epoch();
}
/**
{
// time_t mutt_date_add_timeout(time_t now, long timeout);
- time_t now = time(NULL);
+ time_t now = mutt_date_epoch();
TEST_CHECK(mutt_date_add_timeout(now, -1000) == now);
TEST_CHECK(mutt_date_add_timeout(now, -1) == now);