From 968da847ee0ebe05279adf05320f2966c5b6c549 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Mon, 5 Nov 2001 21:19:33 +0000 Subject: [PATCH] Byrial Jensen's mtime hack is needed at more than one place. Noted by Manoj Kasichainula. --- headers.c | 3 ++- muttlib.c | 29 +++++++++++++++++++++++++++++ protos.h | 1 + send.c | 18 ++---------------- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/headers.c b/headers.c index 1900c836d..c3d23e57a 100644 --- a/headers.c +++ b/headers.c @@ -70,7 +70,8 @@ void mutt_edit_headers (const char *editor, return; } - mtime = st.st_mtime; + mtime = mutt_decrease_mtime (path, &st); + mutt_edit_file (editor, path); stat (path, &st); if (mtime == st.st_mtime) diff --git a/muttlib.c b/muttlib.c index 7f06f71a2..a77c6c127 100644 --- a/muttlib.c +++ b/muttlib.c @@ -40,6 +40,9 @@ #include #include #include +#include +#include +#include BODY *mutt_new_body (void) { @@ -1255,3 +1258,29 @@ void mutt_buffer_add (BUFFER* buf, const char* s, size_t len) buf->dptr += len; *(buf->dptr) = '\0'; } + +/* Decrease a file's modification time by 1 second */ + +time_t mutt_decrease_mtime (const char *f, struct stat *st) +{ + struct utimbuf utim; + struct stat _st; + time_t mtime; + + if (!st) + { + if (stat (f, &_st) == -1) + return -1; + st = &_st; + } + + if ((mtime = st->st_mtime) == time (NULL)) + { + mtime -= 1; + utim.actime = mtime; + utim.modtime = mtime; + utime (f, &utim); + } + + return mtime; +} diff --git a/protos.h b/protos.h index 33eb48157..273594fca 100644 --- a/protos.h +++ b/protos.h @@ -106,6 +106,7 @@ HEADER *mutt_dup_header (HEADER *); ATTACHPTR **mutt_gen_attach_list (BODY *, int, ATTACHPTR **, short *, short *, int, int); +time_t mutt_decrease_mtime (const char *, struct stat *); time_t mutt_local_tz (time_t); time_t mutt_mktime (struct tm *, int); time_t mutt_parse_date (const char *, HEADER *); diff --git a/send.c b/send.c index c9823b111..9a96ef2d5 100644 --- a/send.c +++ b/send.c @@ -1276,22 +1276,8 @@ ci_send_message (int flags, /* send mode */ else if (! (flags & SENDBATCH)) { struct stat st; - time_t mtime; - struct utimbuf utim; - - stat (msg->content->filename, &st); - mtime = st.st_mtime; - if (mtime == time (NULL)) - { - /* Decrease the file's modification time by 1 second so we are sure - * to find out if the `editor' program changes it in less than 1 second. - */ - mtime -= 1; - utim.actime = mtime; - utim.modtime = mtime; - utime (msg->content->filename, &utim); - } - + time_t mtime = mutt_decrease_mtime (msg->content->filename, NULL); + mutt_update_encoding (msg->content); /* If the this isn't a text message, look for a mailcap edit command */ -- 2.40.0