]> granicus.if.org Git - neomutt/commitdiff
Byrial Jensen's mtime hack is needed at more than one place. Noted
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 5 Nov 2001 21:19:33 +0000 (21:19 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 5 Nov 2001 21:19:33 +0000 (21:19 +0000)
by Manoj Kasichainula.

headers.c
muttlib.c
protos.h
send.c

index 1900c836d52d95883bb62081b7ad1bf3088b85a7..c3d23e57aa07b43c264d55bc29847b34c028d4c6 100644 (file)
--- 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)
index 7f06f71a24f28aa794a3884619e7c72e5f52e9cf..a77c6c127a4f825bb95fe04362cb9a6540487352 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -40,6 +40,9 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <time.h>
+#include <sys/types.h>
+#include <utime.h>
 
 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;
+}
index 33eb48157000594062856851091e0199e7acd3dd..273594fca4b72fd5a4347e21543235916541e270 100644 (file)
--- 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 c9823b111f05c138d32c72308ff740290b031731..9a96ef2d5b25f5a1310cb148f7029d4e5fde3141 100644 (file)
--- 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 */