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 2019/01/09 21:59:29 UTC
[whimsy] 02/04: Implement --public option
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch mod-gui
in repository https://gitbox.apache.org/repos/asf/whimsy.git
commit 2d10d3ec8d80e1668226b4e1d0e171fd11efbd9f
Author: Sebb <se...@apache.org>
AuthorDate: Wed Jan 9 16:58:12 2019 +0000
Implement --public option
---
www/moderation/desk/deliver.rb | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/www/moderation/desk/deliver.rb b/www/moderation/desk/deliver.rb
index e574922..8de6aaf 100644
--- a/www/moderation/desk/deliver.rb
+++ b/www/moderation/desk/deliver.rb
@@ -1,13 +1,14 @@
#
# Process email as it is received
-#
-
-#Dir.chdir File.dirname(File.expand_path(__FILE__))
+# A single mail is passed on STDIN
+# The script accepts a CLI parameter 'public' which marks the message as public (i.e. default is private)
require_relative 'models/mailbox'
require 'mail'
require_relative 'config.rb'
+isPublic = ARGV.delete("--public") == '--public'
+
# read and parse email
STDIN.binmode
original = STDIN.read
@@ -41,6 +42,7 @@ begin
domain: dom,
date: hdrs['Date'],
}
+ headers[:public]=true if isPublic
mbox=Mailbox.mboxname(timestamp.to_f)
# construct wrapper message
mailbox = Mailbox.new(mbox)
@@ -53,14 +55,25 @@ begin
message.write_email
# extract the message for main mailbox
email = parts[1].body.raw_source
- elsif subj.start_with? 'CONFIRM subscribe to '
- headers = Hash.new
+ elsif parts.length == 0 && subj.start_with?('CONFIRM subscribe to ')
+ list, dom = subj.sub(/^CONFIRM subscribe to /,'').split'@'
+ hdrs = Mailbox.headers(mail)
+ # N.B. The Reply-To address is the accept address
+ headers = {
+ list: list,
+ domain: dom,
+ accept: hdrs['Reply-To'],
+ }
+ headers[:public]=true if isPublic
email = original
else
$stderr.puts "Unexpected moderation message in #{hash} with subject: #{subj}"
- headers = Hash.new
+ headers = {
+ public: ispublic,
+ }
email = original
- end
+ end
+ # Merge in specific headers from the message
WANTED=%w{Date From To Reply-To Message-ID Subject Return-Path Sender References In-Reply-To}
headers.merge! Message.parse(email).select{ |k,v| Symbol === k or WANTED.include? k }
rescue => e