Project

General

Profile

Bug #1713

IMAP NO response messages are unavailable

Added by drbrain (Eric Hodel) almost 10 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-06-30 trunk 23904) [i386-darwin9.7.0]
Backport:
[ruby-core:24111]

Description

=begin
In RFC 3501 the IMAP server may respond with information the user can use to retry their request.

For the COPY command (6.4.7):

   If the destination mailbox does not exist, a server SHOULD return
   an error.  It SHOULD NOT automatically create the mailbox.  Unless
   it is certain that the destination mailbox can not be created, the
   server MUST send the response code "[TRYCREATE]" as the prefix of
   the text of the tagged NO response.  This gives a hint to the
   client that it can attempt a CREATE command and retry the COPY if
   the CREATE is successful.

Also for the SEARCH command (6.4.4):

   If the server does not support the specified [CHARSET], it MUST
   return a tagged NO response (not a BAD).  This response SHOULD
   contain the BADCHARSET response code, which MAY list the
   [CHARSET]s supported by the server.

Net::IMAP doesn't easily give access to this information. For example:

$ cat imap_copy.rb
require 'net/imap'

Net::IMAP.debug = true
imap = Net::IMAP.new 'localhost', 143
imap.login 'test', 'test'
imap.select 'INBOX'
uids = imap.search 'ALL'
begin
imap.copy uids, 'no such mailbox'
puts 'copy successful'
rescue Net::IMAP::NoResponseError => e
p e
end
$ ruby imap_copy.rb
S: * OK Dovecot ready.
[...]
C: RUBY0004 COPY 1 "no such mailbox"
S: RUBY0004 NO [TRYCREATE] Mailbox doesn't exist: no such mailbox
#

Here the server told us we could probably fix this by sending CREATE first, so we could handle this intelligently. Unfortunately, we can't tell if the mailbox outright doesn't exist or if it simply can't be selected:

irb(main):016:0> imap.list '', 'directory'
C: RUBY0012 LIST "" directory
S: * LIST (\Noselect \HasChildren) "/" "directory"
S: RUBY0012 OK List completed.

irb(main):015:0> imap.copy [1], 'directory'
C: RUBY0011 COPY 1 directory
S: RUBY0011 NO Mailbox isn't selectable: directory

The attached patch adds the response to Net::IMAP::ResponseError which allows us to behave intelligently:

$ cat imap_copy.rb
require 'net/imap'

Net::IMAP.debug = true
imap = Net::IMAP.new 'localhost', 143
imap.login 'test', 'test'
imap.select 'INBOX'
uids = imap.search 'ALL'

begin
imap.copy uids, 'no such mailbox'
puts 'copy successful'
rescue Net::IMAP::NoResponseError => e
raise unless e.response.data.code.name == 'TRYCREATE'
imap.create 'no such mailbox'
imap.copy uids, 'no such mailbox'
end
$ ruby imap_copy.rb
S: * OK Dovecot ready.
[...]
C: RUBY0004 COPY 1 "no such mailbox"
S: RUBY0004 NO [TRYCREATE] Mailbox doesn't exist: no such mailbox
C: RUBY0005 CREATE "no such mailbox"
S: RUBY0005 OK Create completed.
C: RUBY0006 COPY 1 "no such mailbox"
S: RUBY0006 OK [COPYUID 1 64 1] Copy completed.
=end


Files

net_imap_response_in_error.diff (1.54 KB) net_imap_response_in_error.diff Net::IMAP::ResponseError patch to add response to raised exception drbrain (Eric Hodel), 07/02/2009 07:29 AM

History

#2

Updated by shugo (Shugo Maeda) almost 10 years ago

  • Assignee set to shugo (Shugo Maeda)

=begin

=end

#3

Updated by shugo (Shugo Maeda) almost 10 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r23934.
=end

Also available in: Atom PDF