rgrove-larch 1.0.0.11 → 1.0.0.12

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.
data/HISTORY CHANGED
@@ -5,18 +5,18 @@ Version 1.0.1 (?)
5
5
  * Ruby 1.9.1 support.
6
6
  * Much more robust handling of unexpected server disconnects and dropped
7
7
  connections.
8
- * Add --all option to copy all folders recursively.
9
- * Add --dry-run option to simulate changes without actually making them.
10
- * Add --ssl-certs option to specify a bundle of trusted SSL certificates.
11
- * Add --ssl-verify option to verify server SSL certificates.
12
- * Fix excessive post-scan processing times for very large mailboxes.
13
- * Fetch message headers in blocks of up to 1024 at a time rather than all at
14
- once, to prevent potential problems with certain servers when a mailbox
15
- contains a huge number of messages.
16
- * Don't try to trap POSIX signals on platforms that aren't likely to support
17
- them, and don't die if the platform sniffing doesn't save us.
18
- * Add a new "insane" logging level, which will output all IMAP commands and
8
+ * Added --all option to copy all folders recursively.
9
+ * Added --dry-run option to simulate changes without actually making them.
10
+ * Added --ssl-certs option to specify a bundle of trusted SSL certificates.
11
+ * Added --ssl-verify option to verify server SSL certificates.
12
+ * Added a new "insane" logging level, which will output all IMAP commands and
19
13
  responses to STDERR.
14
+ * Fixed excessive post-scan processing times for very large mailboxes.
15
+ * Message headers are now fetched in blocks of up to 1024 at a time rather
16
+ than all at once to prevent potential problems with certain servers when a
17
+ mailbox contains a huge number of messages.
18
+ * POSIX signals are no longer trapped on platforms that aren't likely to
19
+ support them.
20
20
 
21
21
  Version 1.0.0 (2009-03-17)
22
22
  * First release.
@@ -20,7 +20,7 @@ class Mailbox
20
20
  @name = name
21
21
  @delim = delim
22
22
  @subscribed = subscribed
23
- @attr = attr
23
+ @attr = *attr
24
24
 
25
25
  @ids = {}
26
26
  @last_id = 0
@@ -52,7 +52,9 @@ class Mailbox
52
52
  return false if has_message?(message)
53
53
 
54
54
  @imap.safely do
55
- imap_select(!!@imap.options[:create_mailbox])
55
+ unless imap_select(!!@imap.options[:create_mailbox])
56
+ raise Larch::IMAP::Error, "mailbox cannot contain messages: #{@name}"
57
+ end
56
58
 
57
59
  debug "appending message: #{message.id}"
58
60
  @imap.conn.append(@name, message.rfc822, message.flags, message.internaldate) unless @imap.options[:dry_run]
@@ -121,7 +123,7 @@ class Mailbox
121
123
  return if @last_scan && (Time.now - @last_scan) < SCAN_INTERVAL
122
124
 
123
125
  begin
124
- imap_examine
126
+ return unless imap_examine
125
127
  rescue Error => e
126
128
  return if @imap.options[:create_mailbox]
127
129
  raise
@@ -174,7 +176,7 @@ class Mailbox
174
176
  @subscribed
175
177
  end
176
178
 
177
- # Unsubscribes to this mailbox.
179
+ # Unsubscribes from this mailbox.
178
180
  def unsubscribe(force = false)
179
181
  return unless subscribed? || force
180
182
  @imap.safely { @imap.conn.unsubscribe(@name) } unless @imap.options[:dry_run]
@@ -206,7 +208,8 @@ class Mailbox
206
208
  # if it is already selected (which isn't necessary unless you want to ensure
207
209
  # that it's in a read-only state).
208
210
  def imap_examine(force = false)
209
- return if @state == :examined || (!force && @state == :selected)
211
+ return false if @attr.include?(:Noselect)
212
+ return true if @state == :examined || (!force && @state == :selected)
210
213
 
211
214
  @imap.safely do
212
215
  begin
@@ -221,6 +224,8 @@ class Mailbox
221
224
  raise Error, "unable to examine mailbox: #{e.message}"
222
225
  end
223
226
  end
227
+
228
+ return true
224
229
  end
225
230
 
226
231
  # Fetches the specified _fields_ for the specified message sequence id(s) from
@@ -246,7 +251,8 @@ class Mailbox
246
251
  # exist and _create_ is +true+, it will be created. Otherwise, a
247
252
  # Larch::IMAP::Error will be raised.
248
253
  def imap_select(create = false)
249
- return if @state == :selected
254
+ return false if @attr.include?(:Noselect)
255
+ return true if @state == :selected
250
256
 
251
257
  @imap.safely do
252
258
  begin
@@ -270,6 +276,8 @@ class Mailbox
270
276
  end
271
277
  end
272
278
  end
279
+
280
+ return true
273
281
  end
274
282
 
275
283
  # Fetches the specified _fields_ for the specified UID(s) from the IMAP
data/lib/larch/imap.rb CHANGED
@@ -86,6 +86,11 @@ class IMAP
86
86
  safely {} # connect, but do nothing else
87
87
  end
88
88
 
89
+ # Gets the server's mailbox hierarchy delimiter.
90
+ def delim
91
+ @delim ||= safely { @conn.list('', '')[0].delim }
92
+ end
93
+
89
94
  # Closes the IMAP connection if one is currently open.
90
95
  def disconnect
91
96
  return unless @conn
@@ -117,9 +122,11 @@ class IMAP
117
122
  # the mailbox doesn't exist and the +:create_mailbox+ option is +false+, or if
118
123
  # +:create_mailbox+ is +true+ and mailbox creation fails, a
119
124
  # Larch::IMAP::MailboxNotFoundError will be raised.
120
- def mailbox(name)
125
+ def mailbox(name, delim = '/')
121
126
  retries = 0
122
127
 
128
+ name = name.gsub(delim, self.delim)
129
+
123
130
  begin
124
131
  @mailboxes.fetch(name) do
125
132
  update_mailboxes
data/lib/larch/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Larch
2
2
  APP_NAME = 'Larch'
3
- APP_VERSION = '1.0.0.11'
3
+ APP_VERSION = '1.0.0.12'
4
4
  APP_AUTHOR = 'Ryan Grove'
5
5
  APP_EMAIL = 'ryan@wonko.com'
6
6
  APP_URL = 'http://github.com/rgrove/larch/'
data/lib/larch.rb CHANGED
@@ -1,11 +1,10 @@
1
- # Append this file's directory to the include path if it's not there already.
1
+ # Prepend this file's directory to the include path if it's not there already.
2
2
  $:.unshift(File.dirname(File.expand_path(__FILE__)))
3
3
  $:.uniq!
4
4
 
5
5
  require 'cgi'
6
6
  require 'digest/md5'
7
7
  require 'net/imap'
8
- require 'monitor'
9
8
  require 'time'
10
9
  require 'uri'
11
10
 
@@ -39,7 +38,7 @@ module Larch
39
38
  @failed = 0
40
39
  @total = 0
41
40
 
42
- mailbox_to = imap_to.mailbox(mailbox_from.name)
41
+ mailbox_to = imap_to.mailbox(mailbox_from.name, mailbox_from.delim)
43
42
  copy_messages(imap_from, mailbox_from, imap_to, mailbox_to)
44
43
  mailbox_to.subscribe if mailbox_from.subscribed?
45
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgrove-larch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.11
4
+ version: 1.0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Grove