markdown_mail_sender 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/markdown_mail_sender.rb +136 -0
- metadata +88 -0
- metadata.gz.sig +3 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e47bd09ee5de38cd21b2c79250238d6f2ad4b44
|
4
|
+
data.tar.gz: 7ed7221510a648c636f46271a15dbaa69f6664e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 507b9231374792f493ea0e91a43db7ae24ecb2c99f235f47093e1ddfdcc7f410dff0b887000b4a6da3f96c7e8d6935a0b84d90bad293a7b76e3a3bbf74b3c63e
|
7
|
+
data.tar.gz: c9443c75400f473855e466aabe2c6cd2b164f8b28988886d3e8a3607e8e4e1f7b695aa13a5b9a032a7faa4af8684544186a4fae76e0aadbeea72173b7ddced18
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: markdown_mail_sender.rb
|
4
|
+
|
5
|
+
require 'net/smtp'
|
6
|
+
require 'rdiscount'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
|
10
|
+
class MarkdownMailSender
|
11
|
+
|
12
|
+
def initialize(user, password, compose_dir: '~/email/compose',
|
13
|
+
sent_dir: '~/email/sent', smtp_host: nil, from_domain: smtp_host)
|
14
|
+
|
15
|
+
@user, @password = user, password
|
16
|
+
@smtp_host, @mail_from_domain = smtp_host, from_domain
|
17
|
+
|
18
|
+
compose_dirpath = File.expand_path(compose_dir)
|
19
|
+
@sent_dir = File.expand_path(sent_dir)
|
20
|
+
FileUtils.mkdir_p @sent_dir
|
21
|
+
|
22
|
+
# scan the compose directory for email files to deliver
|
23
|
+
|
24
|
+
@messages = Dir.glob(File.join(compose_dirpath, '*.md')).map \
|
25
|
+
do |msg_filepath|
|
26
|
+
|
27
|
+
s = File.read msg_filepath
|
28
|
+
|
29
|
+
regex = %r{
|
30
|
+
|
31
|
+
(?<email>(?:.*<)?\w+(?:\.\w+)?@\S+>?){0}
|
32
|
+
(?<filepath>\s*[\w\/\.]+\s+){0}
|
33
|
+
|
34
|
+
from:\s(?<from>\g<email>)\s+
|
35
|
+
to:\s(?<to>\g<email>)\s+
|
36
|
+
(?:attachments?:\s+(?<attachments>\g<filepath>*))?
|
37
|
+
subject:\s+(?<subject> [^\n]+)\n
|
38
|
+
(?<body> .*)
|
39
|
+
|
40
|
+
}xm =~ s
|
41
|
+
|
42
|
+
files = attachments.nil? ? [] : attachments.split.map(&:strip)
|
43
|
+
|
44
|
+
{
|
45
|
+
filepath: msg_filepath, from: from, to: to, attachments: files,
|
46
|
+
subject: subject, body_txt: body,
|
47
|
+
body_html: RDiscount.new(body).to_html
|
48
|
+
}
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def deliver_all()
|
55
|
+
|
56
|
+
@messages.each.with_index do |x, i|
|
57
|
+
|
58
|
+
puts 'xx: ' + x.inspect
|
59
|
+
|
60
|
+
raw_marker = "AUNIQUEMARKER"
|
61
|
+
marker = "\n--#{raw_marker}"
|
62
|
+
|
63
|
+
from, to, subject = %i(from to subject).map {|name| x[name]}
|
64
|
+
|
65
|
+
header =<<EOF
|
66
|
+
From: #{from}
|
67
|
+
To: #{to}
|
68
|
+
Subject: #{subject}
|
69
|
+
MIME-Version: 1.0
|
70
|
+
Content-Type: multipart/mixed; boundary=#{raw_marker}
|
71
|
+
EOF
|
72
|
+
|
73
|
+
# Define the message action
|
74
|
+
txt_part =<<EOF
|
75
|
+
Content-Type: text/plain
|
76
|
+
Content-Transfer-Encoding:8bit
|
77
|
+
|
78
|
+
#{x[:body_txt]}
|
79
|
+
EOF
|
80
|
+
|
81
|
+
html_part =<<EOF
|
82
|
+
Content-Type: text/html
|
83
|
+
|
84
|
+
#{x[:body_html]}
|
85
|
+
EOF
|
86
|
+
|
87
|
+
a = [header, txt_part, html_part]
|
88
|
+
|
89
|
+
if x[:attachments].any? then
|
90
|
+
|
91
|
+
attachments = x[:attachments].map {|x| file_part x}
|
92
|
+
a.concat attachments
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
mailtext = a.join(marker + "\n") + marker + "--"
|
97
|
+
|
98
|
+
Net::SMTP.start(@smtp_host, 25, @mail_from_domain, @user,
|
99
|
+
@password, :login) do |smtp|
|
100
|
+
|
101
|
+
smtp.send_message mailtext, from, to
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
target = Time.now.strftime("m%d%m%yT%H%Ma")
|
107
|
+
target.succ! while File.exists? target
|
108
|
+
|
109
|
+
FileUtils.mv x[:filepath], File.join(@sent_dir, target + '.md')
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
alias deliver deliver_all
|
116
|
+
|
117
|
+
def file_part(filepath)
|
118
|
+
|
119
|
+
# Read a file and encode it into base64 format
|
120
|
+
|
121
|
+
filecontent = File.read filepath
|
122
|
+
encodedcontent = [filecontent].pack("m") # base64
|
123
|
+
|
124
|
+
filename = File.basename filepath
|
125
|
+
|
126
|
+
<<EOF
|
127
|
+
Content-Type: multipart/mixed; name="#{filename}"
|
128
|
+
Content-Transfer-Encoding:base64
|
129
|
+
Content-Disposition: attachment; filename="#{filename}"
|
130
|
+
|
131
|
+
#{encodedcontent}
|
132
|
+
EOF
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markdown_mail_sender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+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iG9w0BAQUFAAOCAQEARe7NKznl
|
27
|
+
pA17KM+8FuKzf/GEj84lPCKlZxBDNAc8wdnrr37xznO6kBrms68P3uU03pdeCZNQ
|
28
|
+
z9mxoyVP4owdTHOcfLeoLcpeGkHQsDBvPQOUBkrHptUmFTbLB/j9DuT1zddMbBEQ
|
29
|
+
vLrgomspG7090tSqfUcbxtZfyjPbYMTiTXQwoRM0UPk6Sr1A5miAjuIh/BCdyPxw
|
30
|
+
fJvP6El63Ei0f93/BNbRapodjDeZFhDtHht2vnwzpySN11MbZzXQtJY/W6ojR+3n
|
31
|
+
/lI2nqMMq5f39gxDkuM9dlpQCTSlNYaMUH/Ygfnaqi9j9ntJiW9/yjiYUGV7wzeS
|
32
|
+
h4yZiygx7MCysQ==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdiscount
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.2'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.2.0.1
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.2'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.2.0.1
|
56
|
+
description:
|
57
|
+
email: james@r0bertson.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/markdown_mail_sender.rb
|
63
|
+
homepage: https://github.com/jrobertson/markdown_mail_sender
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Sends an email from a file directory containing a Markdown file representing
|
87
|
+
the email message.
|
88
|
+
test_files: []
|
metadata.gz.sig
ADDED