mournmail 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: bce6a83b1d41699944c7440f0737318437931a7e
4
- data.tar.gz: 592a006b174161b564ce302739e19382ef07fda9
3
+ metadata.gz: 624dd4f9dacde981ede7170c87da6c8ddb3a6aae
4
+ data.tar.gz: 9b1890ed2a07cdd551e4688bb88d7a80b1ff2c51
5
5
  SHA512:
6
- metadata.gz: bda483a4723883895517a781308ee8305fc60bc5fab09e6c8ef3181ab770d04304a7f72ccc0b85f23cfa198ae1574ba5ec80c6c9fa961c7a7c17e1da31dc0dd0
7
- data.tar.gz: 79f6879cc3b2737855a3dac77768bda6b440a0303400daa7c8085ae4fb0639c440e6ec0246cfcfc8f4bbefecf8dab6657c57291120e162ee3700f8d88262d939
6
+ metadata.gz: ea1353b03b02800c953d1df9c088400ec1d5698953105f9a0b8c55f1b387d61367061e83f873a891bfbcd73c3bf7a6f17e5a0b539d1cbe16b052b104cb88b18e
7
+ data.tar.gz: 97a308e32677cc6a51490d1be5f4528159760e22866ceef39d33f977ee94fadd3fd95369ab72199baf8d0f5a47cb9daad435b5d0d971e20b2013a82bcc41e2f5
@@ -65,7 +65,7 @@ module Mournmail
65
65
  if !attached_messages.empty?
66
66
  attached_messages.each do |attached_message|
67
67
  mailbox, uid = attached_message.strip.split("/")
68
- s = Mournmail.read_mail(mailbox, uid.to_i)
68
+ s, = Mournmail.read_mail(mailbox, uid.to_i)
69
69
  part = Mail::Part.new(content_type: "message/rfc822", body: s)
70
70
  m.body << part
71
71
  end
@@ -11,8 +11,7 @@ module Mournmail
11
11
  include MonitorMixin
12
12
 
13
13
  def self.cache_path(mailbox)
14
- File.expand_path("cache/#{mailbox}/.summary",
15
- CONFIG[:mournmail_directory])
14
+ File.join(Mournmail.mailbox_cache_path(mailbox), ".summary")
16
15
  end
17
16
 
18
17
  def self.load(mailbox)
@@ -179,7 +178,7 @@ module Mournmail
179
178
  def format_line(limit = 78, from_limit = 16, level = 0)
180
179
  space = " " * (level < 8 ? level : 8)
181
180
  s = String.new
182
- s << format("%s %s%s %s[ %s ] ",
181
+ s << format("%6d %s%s %s[ %s ] ",
183
182
  @uid, format_flags(@flags), format_date(@date), space,
184
183
  ljust(format_from(@from), from_limit))
185
184
  s << ljust(decode_eword(@subject.to_s), limit - Buffer.display_width(s))
@@ -242,20 +241,28 @@ module Mournmail
242
241
  def update_flag(sign, flag, update_server: true)
243
242
  if update_server
244
243
  Mournmail.imap_connect do |imap|
245
- data = imap.uid_store(@uid, "#{sign}FLAGS", [flag]).first
246
- @flags = data.attr["FLAGS"]
244
+ data = imap.uid_store(@uid, "#{sign}FLAGS", [flag])&.first
245
+ if data
246
+ @flags = data.attr["FLAGS"]
247
+ else
248
+ update_flag_local(sign, flag)
249
+ end
247
250
  end
248
251
  else
249
- case
250
- when "+"
251
- @flags.push(flag)
252
- when "-"
253
- @flags.delete(flag)
254
- end
252
+ update_flag_local(sign, flag)
255
253
  end
256
254
  if @line
257
- s = format("%s %s", @uid, format_flags(@flags))
258
- @line.sub!(/^\d+ ./, s)
255
+ s = format("%6d %s", @uid, format_flags(@flags))
256
+ @line.sub!(/^ *\d+ ./, s)
257
+ end
258
+ end
259
+
260
+ def update_flag_local(sign, flag)
261
+ case sign
262
+ when "+"
263
+ @flags.push(flag)
264
+ when "-"
265
+ @flags.delete(flag)
259
266
  end
260
267
  end
261
268
  end
@@ -27,11 +27,11 @@ module Mournmail
27
27
  SUMMARY_MODE_MAP.define_key("j", :next_line)
28
28
  SUMMARY_MODE_MAP.define_key("m", :mournmail_visit_mailbox)
29
29
 
30
- define_syntax :seen, /^\d+ .*/
31
- define_syntax :unseen, /^\d+ u.*/
32
- define_syntax :flagged, /^\d+ \$.*/
33
- define_syntax :deleted, /^\d+ d.*/
34
- define_syntax :answered, /^\d+ a.*/
30
+ define_syntax :seen, /^ *\d+ .*/
31
+ define_syntax :unseen, /^ *\d+ u.*/
32
+ define_syntax :flagged, /^ *\d+ \$.*/
33
+ define_syntax :deleted, /^ *\d+ d.*/
34
+ define_syntax :answered, /^ *\d+ a.*/
35
35
 
36
36
  def initialize(buffer)
37
37
  super(buffer)
@@ -43,7 +43,8 @@ module Mournmail
43
43
  return if uid.nil?
44
44
  Mournmail.background do
45
45
  mailbox = Mournmail.current_mailbox
46
- mail = Mail.new(Mournmail.read_mail(mailbox, uid))
46
+ s, fetched = Mournmail.read_mail(mailbox, uid)
47
+ mail = Mail.new(s)
47
48
  message = mail.render
48
49
  next_tick do
49
50
  message_buffer = Buffer.find_or_new("*message*",
@@ -56,7 +57,7 @@ module Mournmail
56
57
  end
57
58
  window = Mournmail.message_window
58
59
  window.buffer = message_buffer
59
- mark_as_seen(uid)
60
+ mark_as_seen(uid, !fetched)
60
61
  Mournmail.current_uid = uid
61
62
  Mournmail.current_mail = mail
62
63
  end
@@ -99,7 +100,7 @@ module Mournmail
99
100
  uid = selected_uid
100
101
  Mournmail.background do
101
102
  mailbox = Mournmail.current_mailbox
102
- mail = Mail.new(Mournmail.read_mail(mailbox, uid))
103
+ mail = Mail.new(Mournmail.read_mail(mailbox, uid)[0])
103
104
  body = mail.render_body
104
105
  next_tick do
105
106
  Window.current = Mournmail.message_window
@@ -199,7 +200,7 @@ module Mournmail
199
200
  uid = selected_uid
200
201
  Mournmail.background do
201
202
  mailbox = Mournmail.current_mailbox
202
- source = Mournmail.read_mail(mailbox, uid)
203
+ source, = Mournmail.read_mail(mailbox, uid)
203
204
  next_tick do
204
205
  source_buffer = Buffer.find_or_new("*message-source*",
205
206
  file_encoding: "ascii-8bit",
@@ -221,12 +222,12 @@ module Mournmail
221
222
  def selected_uid
222
223
  uid = @buffer.save_excursion {
223
224
  @buffer.beginning_of_line
224
- if !@buffer.looking_at?(/\d+/)
225
+ if !@buffer.looking_at?(/ *\d+/)
225
226
  Mournmail.current_mail = nil
226
227
  Mournmail.current_uid = nil
227
228
  raise EditorError, "No message found"
228
229
  end
229
- match_string(0).to_i
230
+ @buffer.match_string(0).to_i
230
231
  }
231
232
  end
232
233
 
@@ -253,10 +254,10 @@ module Mournmail
253
254
  end
254
255
  end
255
256
 
256
- def mark_as_seen(uid)
257
+ def mark_as_seen(uid, update_server)
257
258
  summary_item = Mournmail.current_summary[uid]
258
259
  if summary_item && !summary_item.flags.include?(:Seen)
259
- summary_item.set_flag(:Seen, update_server: false)
260
+ summary_item.set_flag(:Seen, update_server: update_server)
260
261
  Mournmail.current_summary.save
261
262
  update_flags(summary_item)
262
263
  end
@@ -281,8 +282,8 @@ module Mournmail
281
282
  @buffer.beginning_of_buffer
282
283
  uid = summary_item.uid
283
284
  flags_char = summary_item.flags_char
284
- if @buffer.re_search_forward(/^#{uid} ./)
285
- @buffer.replace_match("#{uid} #{flags_char}")
285
+ if @buffer.re_search_forward(/^( *#{uid}) ./)
286
+ @buffer.replace_match(@buffer.match_string(1) + " " + flags_char)
286
287
  end
287
288
  end
288
289
  end
@@ -294,7 +295,7 @@ module Mournmail
294
295
  raise EditorError, "No more mail"
295
296
  end
296
297
  begin
297
- @buffer.re_search_forward(/^\d+ u/)
298
+ @buffer.re_search_forward(/^ *\d+ u/)
298
299
  rescue SearchError
299
300
  @buffer.forward_line
300
301
  end
@@ -133,13 +133,18 @@ module Mournmail
133
133
  end
134
134
  end
135
135
 
136
+ def self.mailbox_cache_path(mailbox)
137
+ dir = CONFIG[:mournmail_directory]
138
+ host = CONFIG[:mournmail_imap_host]
139
+ File.expand_path("cache/#{host}/#{mailbox}", dir)
140
+ end
141
+
136
142
  def self.read_mail(mailbox, uid)
137
- path = File.expand_path("cache/#{mailbox}/#{uid}",
138
- CONFIG[:mournmail_directory])
143
+ path = File.join(mailbox_cache_path(mailbox), uid.to_s)
139
144
  begin
140
145
  File.open(path) do |f|
141
146
  f.flock(File::LOCK_SH)
142
- f.read
147
+ [f.read, false]
143
148
  end
144
149
  rescue Errno::ENOENT
145
150
  imap_connect do |imap|
@@ -154,7 +159,7 @@ module Mournmail
154
159
  f.flock(File::LOCK_EX)
155
160
  f.write(s)
156
161
  end
157
- s
162
+ [s, true]
158
163
  end
159
164
  end
160
165
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mournmail
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  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: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textbringer