mournmail 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e37a11a19a93dfc9f11a9b9bb98bf3c4c20454668a1d6315627500ec313dc88
4
- data.tar.gz: b8d099a3e67cd35761dab9789f5a3af7c13ebb98f152bf1c031d48d88e4ad69a
3
+ metadata.gz: 55cea609c299af267b279b8434b661ec471776fe26c5175fdc363a527cc3cc7e
4
+ data.tar.gz: b77b32b8fb3923a8e545cd1cd5084dab346974a4f9aa210ae353f76e17839370
5
5
  SHA512:
6
- metadata.gz: 999cb57363f9df4f2bc00eca563b93c61d32c7409e27d628d2ed2c27763af80688886d9b034570ed4291bd92251c5a7c4ae2a8942ea35aa01e7928d365675e8b
7
- data.tar.gz: 96c435e264104b3ebbd1b71d5d561f7a7c207a8c1ee05f1b687192e4811b3b2ef1c7f476a8d2c0655ce452f2e577cfaff5a4c79a9fd28e9d9dc5fbe51944ed3a
6
+ metadata.gz: a891f54dc0e39e09d72a5a8eb9e0272560226fe417eb809462f245bf77e535a9dcaacdf34600e45933723dd0b81378d64e73f1538dcb8c5f2e7c4ffea370078a
7
+ data.tar.gz: f0bee693b1b02a51449e38ca5d001a085f999040be22dcb5d29e1782dffd3dd31698312b9abde9f1fbc57528a72e031df05fa75ed4a6ee2c7535cd318063991e
@@ -13,7 +13,7 @@ module Mournmail
13
13
  # See http://nihongo.jp/support/mail_guide/dev_guide.txt
14
14
  MAILTO_REGEXP = URI.regexp("mailto")
15
15
  URI_REGEXP = /(https?|ftp):\/\/[^  \t\n>)"]*[^]  \t\n>.,:)"]+|#{MAILTO_REGEXP}/
16
- MIME_REGEXP = /^\[(([\-0-9.]+) [A-Za-z._\-]+\/[A-Za-z._\-]+.*|PGP\/MIME .*)\]$/
16
+ MIME_REGEXP = /^\[(([0-9.]+) [A-Za-z._\-]+\/[A-Za-z._\-]+.*|PGP\/MIME .*)\]$/
17
17
  URI_OR_MIME_REGEXP = /#{URI_REGEXP}|#{MIME_REGEXP}/
18
18
 
19
19
  define_syntax :field_name, /^[A-Za-z\-]+: /
@@ -64,7 +64,7 @@ module Mournmail
64
64
  def current_part
65
65
  @buffer.save_excursion do
66
66
  @buffer.beginning_of_line
67
- if @buffer.looking_at?(/\[([\-0-9.]+) .*\]/)
67
+ if @buffer.looking_at?(/\[([0-9.]+) .*\]/)
68
68
  index = match_string(1)
69
69
  indices = index.split(".").map(&:to_i)
70
70
  @buffer[:mournmail_mail].dig_part(*indices)
@@ -130,8 +130,12 @@ module Mournmail
130
130
  else
131
131
  file_name = "mournmail"
132
132
  end
133
- f = Tempfile.open(file_name)
134
- f.write(part.decoded)
133
+ f = Tempfile.open(file_name, binmode: true)
134
+ s = part.decoded
135
+ if part.charset
136
+ s = s.encode(part.charset)
137
+ end
138
+ f.write(s)
135
139
  f.close
136
140
  if ext == "txt"
137
141
  find_file(f.path)
@@ -1,4 +1,5 @@
1
1
  require "mail"
2
+ require "html2text"
2
3
 
3
4
  module Mournmail
4
5
  module MessageRendering
@@ -27,16 +28,21 @@ module Mournmail
27
28
  end
28
29
  if multipart?
29
30
  parts.each_with_index.map { |part, i|
30
- part.render([*indices, i])
31
+ no_content = sub_type == "alternative" && i > 0
32
+ part.render([*indices, i], no_content)
31
33
  }.join
32
- elsif main_type.nil? || (main_type == "text" && sub_type == "plain")
33
- s = body.decoded
34
- Mournmail.to_utf8(s, charset)
34
+ elsif main_type.nil? || main_type == "text"
35
+ s = Mournmail.to_utf8(body.decoded, charset)
36
+ if sub_type == "html"
37
+ "[0 text/html]\n" + Html2Text.convert(s)
38
+ else
39
+ s
40
+ end
35
41
  else
36
42
  type = Mail::Encodings.decode_encode(self["content-type"].to_s,
37
43
  :decode) rescue
38
44
  "broken/type; error=\"#{$!} (#{$!.class})\""
39
- "[-1 #{type}]\n"
45
+ "[0 #{type}]\n"
40
46
  end + pgp_signature
41
47
  end
42
48
 
@@ -45,10 +51,10 @@ module Mournmail
45
51
  mail = decrypt(verify: true)
46
52
  return mail.dig_part(i, *rest_indices)
47
53
  end
48
- if i == -1
54
+ if i == 0
49
55
  return self
50
56
  end
51
- part = parts[i]
57
+ part = parts[i - 1]
52
58
  if rest_indices.empty?
53
59
  part
54
60
  else
@@ -79,12 +85,13 @@ module Mournmail
79
85
  end
80
86
 
81
87
  refine ::Mail::Part do
82
- def render(indices)
83
- index = indices.join(".")
88
+ def render(indices, no_content = false)
89
+ index = indices.map { |i| i + 1 }.join(".")
84
90
  type = Mail::Encodings.decode_encode(self["content-type"].to_s,
85
91
  :decode) rescue
86
92
  "broken/type; error=\"#{$!} (#{$!.class})\""
87
- "[#{index} #{type}]\n" + render_content(indices)
93
+ "[#{index} #{type}]\n" +
94
+ (no_content ? "" : render_content(indices))
88
95
  end
89
96
 
90
97
  def dig_part(i, *rest_indices)
@@ -92,7 +99,7 @@ module Mournmail
92
99
  mail = Mail.new(body.to_s)
93
100
  mail.dig_part(i, *rest_indices)
94
101
  else
95
- part = parts[i]
102
+ part = parts[i - 1]
96
103
  if rest_indices.empty?
97
104
  part
98
105
  else
@@ -106,7 +113,8 @@ module Mournmail
106
113
  def render_content(indices)
107
114
  if multipart?
108
115
  parts.each_with_index.map { |part, i|
109
- part.render([*indices, i])
116
+ no_content = sub_type == "alternative" && i > 0
117
+ part.render([*indices, i], no_content)
110
118
  }.join
111
119
  elsif main_type == "message" && sub_type == "rfc822"
112
120
  mail = Mail.new(body.raw_source)
@@ -114,8 +122,12 @@ module Mournmail
114
122
  elsif attachment?
115
123
  ""
116
124
  else
117
- if main_type == "text" && sub_type == "plain"
118
- decoded.sub(/(?<!\n)\z/, "\n").gsub(/\r\n/, "\n")
125
+ if main_type == "text"
126
+ if sub_type == "html"
127
+ Html2Text.convert(decoded).sub(/(?<!\n)\z/, "\n")
128
+ else
129
+ decoded.sub(/(?<!\n)\z/, "\n").gsub(/\r\n/, "\n")
130
+ end
119
131
  else
120
132
  ""
121
133
  end
@@ -1,3 +1,3 @@
1
1
  module Mournmail
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/mournmail.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_runtime_dependency "rroonga"
28
28
  spec.add_runtime_dependency "google-api-client"
29
29
  spec.add_runtime_dependency "launchy"
30
+ spec.add_runtime_dependency "html2text"
30
31
 
31
32
  spec.add_development_dependency "bundler"
32
33
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mournmail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textbringer
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: html2text
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -172,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
186
  - !ruby/object:Gem::Version
173
187
  version: '0'
174
188
  requirements: []
175
- rubygems_version: 3.2.3
189
+ rubygems_version: 3.3.0.dev
176
190
  signing_key:
177
191
  specification_version: 4
178
192
  summary: A message user agent for Textbringer.