mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2010-03-08 10:09 pm

[dw-free] Date of posts submitted by email

[commit: http://hg.dwscoalition.org/dw-free/rev/8bd7822e342b]

http://bugs.dwscoalition.org/show_bug.cgi?id=2142

Use Date header or post-date option to allow emailed posts to have a custom
date.

Patch by [personal profile] noodles.

Files modified:
  • bin/checkconfig.pl
  • cgi-bin/ljemailgateway.pl
--------------------------------------------------------------------------------
diff -r 6e52432d0978 -r 8bd7822e342b bin/checkconfig.pl
--- a/bin/checkconfig.pl	Mon Mar 08 19:38:35 2010 +0000
+++ b/bin/checkconfig.pl	Mon Mar 08 22:09:09 2010 +0000
@@ -70,6 +70,7 @@ my $err = sub {
 };
 
 my %modules = (
+               "Date::Parse" => { 'deb' => 'libtimedate-perl' },
                "DateTime" => { 'deb' => 'libdatetime-perl' },
                "DBI" => { 'deb' => 'libdbi-perl',  },
                "DBD::mysql" => { 'deb' => 'libdbd-mysql-perl', },
diff -r 6e52432d0978 -r 8bd7822e342b cgi-bin/ljemailgateway.pl
--- a/cgi-bin/ljemailgateway.pl	Mon Mar 08 19:38:35 2010 +0000
+++ b/cgi-bin/ljemailgateway.pl	Mon Mar 08 22:09:09 2010 +0000
@@ -31,6 +31,7 @@ require 'ljlib.pl';
 require 'ljlib.pl';
 require 'ljemailgateway-web.pl';
 require 'ljprotocol.pl';
+use Date::Parse;
 use HTML::Entities;
 use IO::Handle;
 use MIME::Words ();
@@ -393,6 +394,10 @@ sub process {
     # trim off excess whitespace (html cleaner converts to breaks)
     $body =~ s/\n+$/\n/;
 
+    # Pull the Date: header details
+    my ( $ss, $mm, $hh, $day, $month, $year, $zone ) =
+            strptime( $head->get( 'Date:' ) );
+
     # Find and set entry props.
     my $props = {};
     my (%post_headers, $amask);
@@ -406,6 +411,13 @@ sub process {
         $post_headers{lc($1)} = LJ::trim($2);
     }
     $body =~ s/^\s*//;
+
+    # If we had an lj/post-date pseudo header, override the real Date header
+    ( $ss, $mm, $hh, $day, $month, $year, $zone ) =
+        strptime( $post_headers{date} ) if $post_headers{date};
+
+    # TZ is parsed into seconds, we want something more like -0800
+    $zone = defined $zone ? sprintf( '%+05d', $zone / 36 ) : 'guess';
 
     LJ::load_user_props(
         $u,
@@ -505,15 +517,20 @@ sub process {
 
     # build lj entry
     $req = {
-        'usejournal' => $journal,
-        'ver' => 1,
-        'username' => $user,
-        'event' => $body,
-        'subject' => $subject,
-        'security' => $post_headers{security},
-        'allowmask' => $amask,
-        'props' => $props,
-        'tz'    => 'guess',
+        usejournal  => $journal,
+        ver         => 1,
+        username    => $user,
+        event       => $body,
+        subject     => $subject,
+        security    => $post_headers{security},
+        allowmask   => $amask,
+        props       => $props,
+        tz          => $zone,
+        year        => $year + 1900,
+        mon         => $month + 1,
+        day         => $day,
+        hour        => $hh,
+        min         => $mm,
     };
 
     # post!
--------------------------------------------------------------------------------