-message_from_status message date status =
- message { subject = "Twat: " ++ (screen_name (user status)),
- body = (pretty_print status),
- headers = ((headers message) ++ ["Date: " ++ date])}
-
-
--- |This is the main recursive loop. It takes a username, a
--- latest_status_id, and optionally a 'Message' as arguments. The
--- latest_status_id is the last status (that we know of) to be posted
--- to username's Twitter account. If we find any newer statuses when
--- we check, they are printed and optionally emailed (if a 'Message'
--- was supplied). Then, the process repeats.
-recurse :: String -> Integer -> (Maybe Message) -> IO ()
-recurse username latest_status_id maybe_message = do
- thread_sleep heartbeat
+message_from_status message default_date status =
+ message { subject = "Twat: " ++ (screen_name (user status)),
+ body = (pretty_print status),
+ headers = ((headers message) ++ ["Date: " ++ date])}
+ where
+ -- Use the Status' created_at date if it can be coerced into
+ -- RFC822 format.
+ date = case (created_at_to_rfc822 $ created_at status) of
+ Nothing -> default_date
+ Just c -> c
+
+-- |This is the main recursive loop. It takes a length of time to
+-- delay (in seconds), a username, a latest_status_id, and optionally
+-- a 'Message' as arguments. The latest_status_id is the last status
+-- (that we know of) to be posted to username's Twitter account. If we
+-- find any newer statuses when we check, they are printed and
+-- optionally emailed (if a 'Message' was supplied). Then, the process
+-- repeats.
+recurse :: Int -> String -> Integer -> (Maybe Message) -> IO ()
+recurse delay username latest_status_id maybe_message = do
+ thread_sleep delay