mournmail 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2cbdbd1f9d9fe5f74f7d098cbf1eae74e113d544705005a9ca95f652799c7e3
4
- data.tar.gz: 384b036461c6ea691d7559bb17fec0c2439ebebf51e5694e49481844d25336a5
3
+ metadata.gz: 140daea6492012b5093229b435fdbe2c98548430b8b8a74a0714483dd039c085
4
+ data.tar.gz: cb3fb9f8bd0a43fce73f3bd2d3e1d9515acaf74c1a3246c429c027ea7f9db140
5
5
  SHA512:
6
- metadata.gz: 18831f3e5fff6e0a181791c56a926c866cfef9f2b210e5f47f7f0bca04c73695130cdd3f9924b9a7e359e1f479e878ea1c8c157092162e366513e62a9111eca3
7
- data.tar.gz: b252222b12d59b599df9f81f5b610dff5649c0440782e89ca273602039738b8a3708f6499560ad461c88844a14c0bcb2e9216ddb21dbdd00471a82de52e71569
6
+ metadata.gz: dbfe86922c8b715349fd6d22443e0222b58b6b4c6ea64e78a3cfc01b1caa8f9b4852796a381556f536a9cc8608db8203e69de17c7ce47d4172e03392c34a0847
7
+ data.tar.gz: 4437171b2b8baa965d829c30f1807d0c23b459dd0b5c5756b54fd728177d0e3af2df6702939b155f80913fb254d49303aee6123047509a0f44643e471feb03d0
@@ -36,4 +36,21 @@ module Textbringer
36
36
  end
37
37
  CONFIG[:mournmail_addresses_path] = File.expand_path("~/.addresses")
38
38
  CONFIG[:mournmail_signature_regexp] = /^\n-- /
39
+ CONFIG[:mournmail_allowed_attachment_extensions] = [
40
+ "txt",
41
+ "md",
42
+ "htm",
43
+ "html",
44
+ "pdf",
45
+ "jpg",
46
+ "jpeg",
47
+ "png",
48
+ "gif",
49
+ "doc",
50
+ "docx",
51
+ "xls",
52
+ "xlsx",
53
+ "ppt",
54
+ "zip"
55
+ ]
39
56
  end
@@ -129,6 +129,14 @@ module Mournmail
129
129
  raise EditorError, "Can't open a multipart entity."
130
130
  end
131
131
  ext = part_file_name(part).slice(/\.([^.]+)\z/, 1)
132
+ if part.main_type != "text" || part.sub_type == "html"
133
+ if ext.nil?
134
+ raise EditorError, "The extension of the filename is not specified"
135
+ end
136
+ if !CONFIG[:mournmail_allowed_attachment_extensions].include?(ext)
137
+ raise EditorError, ".#{ext} is not allowed"
138
+ end
139
+ end
132
140
  if ext
133
141
  file_name = ["mournmail", "." + ext]
134
142
  else
@@ -11,6 +11,7 @@ require 'google/api_client/client_secrets'
11
11
  require 'google/api_client/auth/storage'
12
12
  require 'google/api_client/auth/storages/file_store'
13
13
  require 'launchy'
14
+ require "socket"
14
15
 
15
16
  class Net::SMTP
16
17
  def auth_xoauth2(user, secret)
@@ -225,6 +226,41 @@ module Mournmail
225
226
  end
226
227
  end
227
228
 
229
+ class GoogleAuthCallbackServer
230
+ def initialize
231
+ @servers = Socket.tcp_server_sockets("127.0.0.1", 0)
232
+ end
233
+
234
+ def port
235
+ @servers.first.local_address.ip_port
236
+ end
237
+
238
+ def receive_code
239
+ Socket.accept_loop(@servers) do |sock, addr|
240
+ line = sock.gets
241
+ query_string = line.slice(%r'\AGET [^?]*\?(.*) HTTP/1.1\r\n', 1)
242
+ params = CGI.parse(query_string)
243
+ code = params["code"][0]
244
+ while line = sock.gets
245
+ break if line == "\r\n"
246
+ end
247
+ sock.print("HTTP/1.1 200 OK\r\n")
248
+ sock.print("Content-Type: text/plain\r\n")
249
+ sock.print("\r\n")
250
+ if code
251
+ sock.print("Authenticated!")
252
+ else
253
+ sock.print("Authentication failed!")
254
+ end
255
+ return code
256
+ ensure
257
+ sock.close
258
+ end
259
+ ensure
260
+ @servers.each(&:close)
261
+ end
262
+ end
263
+
228
264
  def self.google_access_token(account = current_account)
229
265
  auth_path = File.expand_path("cache/#{account}/google_auth.json",
230
266
  CONFIG[:mournmail_directory])
@@ -236,28 +272,21 @@ module Mournmail
236
272
  conf = CONFIG[:mournmail_accounts][account]
237
273
  path = File.expand_path(conf[:client_secret_path])
238
274
  client_secrets = Google::APIClient::ClientSecrets.load(path)
275
+ callback_server = GoogleAuthCallbackServer.new
239
276
  auth_client = client_secrets.to_authorization
240
277
  auth_client.update!(
241
278
  :scope => 'https://mail.google.com/',
242
- :redirect_uri => 'urn:ietf:wg:oauth:2.0:oob'
279
+ :redirect_uri => "http://127.0.0.1:#{callback_server.port}/"
243
280
  )
244
281
  auth_uri = auth_client.authorization_uri.to_s
245
- auth_client.code = foreground! {
282
+ foreground! do
246
283
  begin
247
284
  Launchy.open(auth_uri)
248
285
  rescue Launchy::CommandNotFoundError
249
- buffer = show_google_auth_uri(auth_uri)
286
+ show_google_auth_uri(auth_uri)
250
287
  end
251
- begin
252
- Window.echo_area.clear_message
253
- Window.redisplay
254
- read_from_minibuffer("Code: ").chomp
255
- ensure
256
- if buffer
257
- kill_buffer(buffer, force: true)
258
- end
259
- end
260
- }
288
+ end
289
+ auth_client.code = callback_server.receive_code
261
290
  auth_client.fetch_access_token!
262
291
  old_umask = File.umask(077)
263
292
  begin
@@ -1,3 +1,3 @@
1
1
  module Mournmail
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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: 1.0.1
4
+ version: 1.0.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: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textbringer