markdown_gmail_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_gmail_sender.rb +80 -0
- metadata +108 -0
- metadata.gz.sig +5 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16edcd6d9d8c24ffd88b041a29cdb28ea90f757c
|
4
|
+
data.tar.gz: 904994b98bcec5d7d46f2b17c940deae419c384d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12c24b154fc4a4ddf7cc7fa05f2417a58ee0f93c007c51b4ca3d431b92f5c0ea71a6afa9d3ec8883e6d64606cad5a5f73191eb95b2b2f64195dfd9c961595f5d
|
7
|
+
data.tar.gz: 1d6e51ad9146b88d5604eef62bff26a0b1d38188f75c91f4d805a6bc399219ae2d7bda2e6d44e3b38074089d1c999cf5e6d0a2f96b7ebf4dd5d6a9c324d93673
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: markdown_gmail_sender.rb
|
4
|
+
|
5
|
+
require 'gmail'
|
6
|
+
require 'rdiscount'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
|
10
|
+
class MarkdownGmailSender
|
11
|
+
|
12
|
+
def initialize(accounts={}, compose_dir: '~/email/compose',
|
13
|
+
sent_dir: '~/email/sent')
|
14
|
+
|
15
|
+
@accounts = accounts
|
16
|
+
|
17
|
+
compose_dirpath = File.expand_path(compose_dir)
|
18
|
+
@sent_dir = File.expand_path(sent_dir)
|
19
|
+
FileUtils.mkdir_p @sent_dir
|
20
|
+
|
21
|
+
# scan the compose directory for email files to deliver
|
22
|
+
|
23
|
+
@messages = Dir.glob(File.join(compose_dirpath, '*.md')).map do |filepath|
|
24
|
+
|
25
|
+
s = File.read filepath
|
26
|
+
|
27
|
+
from = s[/from: ([\S]+)/,1]
|
28
|
+
to = s[/to: ([\S]+)/,1]
|
29
|
+
subject = s[/subject: ([^\n]+)/,1]
|
30
|
+
subject_line = s.lines.detect{|x| x =~ /subject: / }
|
31
|
+
body = s.lines[(s.lines.index(subject_line) + 1) .. -1].join.strip
|
32
|
+
|
33
|
+
{
|
34
|
+
filepath: filepath,
|
35
|
+
from: from, to: to,
|
36
|
+
subject: subject,
|
37
|
+
body_txt: body, body_html: RDiscount.new(body).to_html
|
38
|
+
}
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def deliver_all()
|
45
|
+
|
46
|
+
@messages.each.with_index do |x, i|
|
47
|
+
|
48
|
+
username, password = x[:from], @accounts[x[:from]]
|
49
|
+
gmail = Gmail.new(username, password)
|
50
|
+
|
51
|
+
gmail.deliver do
|
52
|
+
|
53
|
+
to x[:to]
|
54
|
+
subject x[:subject]
|
55
|
+
|
56
|
+
text_part do
|
57
|
+
body x[:body_txt]
|
58
|
+
end
|
59
|
+
|
60
|
+
html_part do
|
61
|
+
content_type 'text/html; charset=UTF-8'
|
62
|
+
body x[:body_html]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
target = Time.now.strftime("m%d%m%yT%H%Ma")
|
68
|
+
target.succ! while File.exists? target
|
69
|
+
|
70
|
+
FileUtils.mv x[:filepath], File.join(@sent_dir, target + '.md')
|
71
|
+
|
72
|
+
puts "message #{(i+1).to_s} sent"
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
alias deliver deliver_all
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markdown_gmail_sender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
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ydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAXcDK1aT1
|
27
|
+
sffllr3kKSq+QTHc3Elx7hHs8qoPvrBSgLm2kSF+8qlYS22g6vh/LYDzMfyhpib2
|
28
|
+
gCPUe++7f5ZaBdYCxbWu43h9y08OQdCx8G+cYZEmwP30HRBp61kMspVK0Dh3IUP5
|
29
|
+
N2JxwyVzFZnSQeiPCAiYgPfbB9SvpFI/VU9v/i75hnsP4amE7pcCe14rMsEgepo0
|
30
|
+
+q0g0nvJmpTYUKk6IfEQFzljhj988cTfdR4mBKEUyayetj0ybG6DGe8soEl771Cb
|
31
|
+
OLGmpGkaE9Sobz20K+IVp5+s3z06CrVYK7TN2gXYiGZRGAxmnd3sd0F8Aewu4uWI
|
32
|
+
HiWyElQDGz9Bjw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-05-30 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: gmail
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.6'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.6.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.6'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rdiscount
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.2'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.2.0.1
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.2'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.2.0.1
|
76
|
+
description:
|
77
|
+
email: james@r0bertson.co.uk
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- lib/markdown_gmail_sender.rb
|
83
|
+
homepage: https://github.com/jrobertson/markdown_gmail_sender
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Scans a *compose* folder (file directory) for messages (files in markdown
|
107
|
+
format) to send using the gmail gem.
|
108
|
+
test_files: []
|