feed2email 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,84 +0,0 @@
1
- require 'mail'
2
- require 'feed2email/configurable'
3
- require 'feed2email/version'
4
-
5
- module Feed2Email
6
- class Mail
7
- include Configurable
8
-
9
- def initialize(entry, feed_title)
10
- @entry = entry
11
- @feed_title = feed_title
12
- end
13
-
14
- def send
15
- build_mail.deliver!
16
- end
17
-
18
- private
19
-
20
- def body_html
21
- %{
22
- <html>
23
- <body>
24
- <h1><a href="%{uri}">%{title}</a></h1>
25
- %{content}
26
- <p>%{published}</p>
27
- <p><a href="%{uri}">%{uri}</a></p>
28
- <p>--<br>
29
- Sent by <a href="https://github.com/agorf/feed2email">feed2email
30
- #{VERSION}</a> at #{Time.now}</p>
31
- </body>
32
- </html>
33
- }.gsub(/^\s+/, '') % {
34
- content: entry.content,
35
- published: published,
36
- title: entry.title.strip_html,
37
- uri: entry.uri.escape_html,
38
- }
39
- end
40
-
41
- def body_text
42
- body_html.to_markdown
43
- end
44
-
45
- def build_mail
46
- ::Mail.new.tap do |m|
47
- m.from = %{"#{feed_title}" <#{config['sender']}>}
48
- m.to = config['recipient']
49
- m.subject = entry.title.strip_html
50
- m.html_part = build_mail_part('text/html', body_html)
51
- m.text_part = build_mail_part('text/plain', body_text)
52
-
53
- m.delivery_method(*delivery_method_params)
54
- end
55
- end
56
-
57
- def build_mail_part(content_type, body)
58
- part = ::Mail::Part.new
59
- part.content_type = "#{content_type}; charset=UTF-8"
60
- part.body = body
61
- part
62
- end
63
-
64
- def delivery_method_params
65
- if config.smtp_configured?
66
- [:smtp_connection, connection: Feed2Email.smtp_connection]
67
- else
68
- [:sendmail, location: config['sendmail_path']]
69
- end
70
- end
71
-
72
- def entry; @entry end
73
-
74
- def feed_title; @feed_title end
75
-
76
- def published
77
- return nil unless entry.author || entry.published
78
- text = 'Published'
79
- text << " by #{entry.author}" if entry.author
80
- text << " at #{entry.published}" if entry.published
81
- text
82
- end
83
- end
84
- end