IMAP: unexpected token LPAR (expected QUOTED or LITERAL)

S

Shea Barton

I'm writing an IMAP parser that uses BODYSTRUCTURE to fetch only the
text (not attachments) part of an email. On a few messages, ruby errors
out on imap.fetch id, "BODYSTRUCTURE", with
"Net::IMAP::ResponseParseError: unexpected token LPAR (expected QUOTED
or LITERAL)". I would just rescue it, but it breaks the connection as
well, raising "OpenSSL::SSL::SSLError: SSL_write:: unexpected record"
for any further fetches.

The only two other topics on this I have found have patches, but for
earlier versions of ruby, which I have been unable to adapt.
http://rubyforge.org/tracker/index.php?func=detail&aid=3983&group_id=426&atid=1698
https://www.ruby-forum.com/topic/87177

Help?
 
S

Shea Barton

Heres the full trace, with Net::IMAP.debug = true

C: RUBY0003 FETCH 3398 bodystructure
S: * 3398 FETCH (BODYSTRUCTURE (("ALTERNATIVE" ("BOUNDARY"
"==alternative_xad5934455aeex") NIL NIL)("TEXT" "HTML" ("CHARSET"
"iso-8859-1" "NAME" "seti_letter.html") NIL NIL "7BIT" 6777 171 NIL NIL
NIL) "ALTERNATIVE" ("BOUNDARY" "==alternative_xad5934455aeex") NIL NIL))
@str: "* 3398 FETCH (BODYSTRUCTURE ((\"ALTERNATIVE\" (\"BOUNDARY\"
\"==alternative_xad5934455aeex\") NIL NIL)(\"TEXT\" \"HTML\"
(\"CHARSET\" \"iso-8859-1\" \"NAME\" \"seti_letter.html\") NIL NIL
\"7BIT\" 6777 171 NIL NIL NIL) \"ALTERNATIVE\" (\"BOUNDARY\"
\"==alternative_xad5934455aeex\") NIL NIL))\r\n"
@pos: 45
@lex_state: EXPR_DATA
@token.symbol: LPAR
@token.value: "("
Net::IMAP::ResponseParseError: unexpected token LPAR (expected QUOTED or
LITERAL)
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:3156:in
`parse_error'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:3008:in
`match'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2956:in
`case_insensitive_string'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2286:in
`media_type'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2219:in
`body_type_basic'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2214:in
`body_type_1part'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2198:in
`body'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2273:in
`body_type_mpart'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2196:in
`body'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2173:in
`body_data'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2085:in
`msg_att'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:2055:in
`numeric_response'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:1997:in
`response_untagged'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:1977:in
`response'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:1903:in
`parse'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:1028:in
`get_response'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:936:in
`receive_responses'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:926:in
`initialize'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:925:in
`start'
from
/Users/shea/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/net/imap.rb:925:in
`initialize'
from (irb):3:in `new'
from (irb):3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top