You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2020/06/01 16:33:59 UTC

[whimsy] branch master updated: Initial draft of script to generate email summaries

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 24a77c4  Initial draft of script to generate email summaries
24a77c4 is described below

commit 24a77c440c0f94cdc581d2ab00ad48b08e4ce984
Author: Sebb <se...@apache.org>
AuthorDate: Mon Jun 1 17:33:40 2020 +0100

    Initial draft of script to generate email summaries
---
 tools/parsemail.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/tools/parsemail.rb b/tools/parsemail.rb
new file mode 100755
index 0000000..1a7082c
--- /dev/null
+++ b/tools/parsemail.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+
+#
+# Parse mail files and update summary YAML file
+#
+
+# DRAFT DRAFT DRAFT DRAFT
+#
+# Could perhaps be incorporated into the deliver script, once proven
+
+
+$LOAD_PATH.unshift '/srv/whimsy/lib'
+require 'whimsy/asf/yaml'
+
+require 'mail'
+
+MAIL_ROOT = '/srv/mail'
+
+list = ARGV.shift || 'board' # provide the list on the command line (e.g. board)
+yyyymm = ARGV.shift || Time.now.strftime('%Y%m')
+yamlfile = ARGV.shift || File.join(MAIL_ROOT, list, "#{yyyymm}.yaml") # where to find the YAML summary
+
+maildir = File.join(MAIL_ROOT, list, yyyymm) # where to find the mail files
+
+data = Hash.new
+
+begin
+  current = YamlFile.read(yamlfile)
+rescue Errno::ENOENT
+  current = {}
+end
+
+Dir.glob("#{maildir}/[0-9a-f][0-9a-f]*").each do |p|
+    name = File.basename(p)
+    unless current[name]
+        mail=Mail.read(p)
+        entry = {
+            Subject:   mail.subject,
+            Date:      (mail['Date'].decoded rescue ''), # textual
+            DateParsed: (mail.date.to_s rescue ''), # parsed
+            From:      (mail['From'].decoded rescue ''),
+            To:        (mail['To'].decoded rescue ''),
+            Cc:        (mail['Cc'].decoded rescue ''),
+            # list of destination emails
+            Emails:     [(mail[:to].addresses.map(&:to_str) rescue []),(mail[:cc].addresses.map(&:to_str) rescue [])].flatten,
+            MessageId: mail.message_id, # could be nil
+            EnvelopeFrom: mail.envelope_from,
+        }
+        data[name] = entry
+    end
+end
+
+# update the file with any new entries
+YamlFile.update(yamlfile) do |yaml|
+    data.each do |k,v|
+        unless yaml[k] # don't update existing entries
+            yaml[k] = v
+        end
+    end
+end