about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs23
3 files changed, 22 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 71b2e02..21b3539 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -507,6 +507,7 @@ dependencies = [
 name = "pushmail"
 version = "0.1.0"
 dependencies = [
+ "chrono",
  "clap",
  "failure",
  "graphql_client",
diff --git a/Cargo.toml b/Cargo.toml
index 900838a..2f8740e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -54,3 +54,4 @@ failure = "0.1.6"
 isahc = { version = "0.8.2", features = ["json"] }
 libc = "0.2.68"
 clap = "2.33.0"
+chrono = "0.4.11"
diff --git a/src/main.rs b/src/main.rs
index e2587f8..4120c0d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -41,6 +41,7 @@
 
 mod util;
 
+use chrono::prelude::*;
 use clap::clap_app;
 use failure::{err_msg, format_err, Error};
 use isahc::prelude::*;
@@ -151,7 +152,7 @@ impl<S: AsRef<OsStr>> Git<S> {
         argv.extend_from_slice(&c_global_args);
         argv.push(b"show\0" as *const _);
         argv.push(b"--no-patch\0" as *const _);
-        argv.push(b"--format=Committer: %cn <%ce>\0" as *const _);
+        argv.push(b"--format=Date: %aD%nCommit: %cn <%ce>%nCommitDate: %cD\0" as *const _);
         argv.push(range.as_ptr());
         argv.push(null());
 
@@ -380,6 +381,7 @@ impl<'a> Run<'a> {
 
         for line in patch {
             let line = line?;
+            let mut write = true;
 
             let new_state = match (state, line.as_slice()) {
                 (Header, b"") => MessageHeader,
@@ -390,6 +392,19 @@ impl<'a> Run<'a> {
             };
 
             match (state, new_state) {
+                (Header, Header) => {
+                    if line
+                        .iter()
+                        .map(u8::to_ascii_lowercase)
+                        .take(5)
+                        .collect::<Vec<_>>()
+                        == b"date:"
+                    {
+                        write!(sendmail_in, "Date: {}\n", Local::now().to_rfc2822())?;
+                        write = false;
+                    }
+                }
+
                 (MessageHeader, Message) => {
                     self.git
                         .git_print_user_info(sendmail_in, OsStr::new(commit))?;
@@ -402,8 +417,10 @@ impl<'a> Run<'a> {
                 _ => {}
             }
 
-            sendmail_in.write_all(&line)?;
-            sendmail_in.write_all(b"\n")?;
+            if write {
+                sendmail_in.write_all(&line)?;
+                sendmail_in.write_all(b"\n")?;
+            }
 
             state = new_state;
         }