Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while trying to backup #16

Closed
martinjuhasz opened this issue May 10, 2014 · 6 comments
Closed

error while trying to backup #16

martinjuhasz opened this issue May 10, 2014 · 6 comments

Comments

@martinjuhasz
Copy link

got this error while importing, did fine some minutes, then crashed with this:

/Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/elements/received_element.rb:10:in `parse': invalid date (ArgumentError)
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/elements/received_element.rb:10:in `initialize'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/fields/received_field.rb:38:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/fields/received_field.rb:38:in `parse'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/fields/received_field.rb:31:in `initialize'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/field.rb:203:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/field.rb:203:in `new_field'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/field.rb:192:in `create_field'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/field.rb:115:in `initialize'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:93:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:93:in `block in fields='
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:91:in `each'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:91:in `fields='
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:269:in `split_header'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/header.rb:54:in `initialize'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:407:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:407:in `header='
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:1972:in `parse_message'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:2103:in `init_with_string'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:128:in `initialize'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/mail.rb:50:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/mail-2.5.4/lib/mail/mail.rb:50:in `new'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/email/mboxrd/message.rb:19:in `parsed'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/email/mboxrd/message.rb:23:in `from'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/email/mboxrd/message.rb:13:in `to_s'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/serializer/mbox.rb:35:in `save'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/downloader.rb:16:in `block in run'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/downloader.rb:13:in `each'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/downloader.rb:13:in `run'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/account/connection.rb:31:in `block in run_backup'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/account/connection.rb:27:in `each'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/account/connection.rb:27:in `run_backup'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/bin/imap-backup:63:in `block in <top (required)>'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/configuration/list.rb:23:in `block in each_connection'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/configuration/list.rb:21:in `each'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/imap/backup/configuration/list.rb:21:in `each_connection'
    from /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/bin/imap-backup:62:in `<top (required)>'
    from /Users/username/.rbenv/versions/2.0.0-p247/bin/imap-backup:23:in `load'
    from /Users/username/.rbenv/versions/2.0.0-p247/bin/imap-backup:23:in `<main>'
@joeyates
Copy link
Owner

So, it looks like the 'Mail' gem is failing to parse one of the date headers of an email, and imap-backup is not handling the error.

The only solution I can see within imap-backup is to trap errors like this and log the fact that the email cannot be backed up (and maybe dump the contents of the email). I don't really like that solution as users might not see the log message and might end up relying on backups that are partial.

An alternative is to debug the failure within Mail and try to see if it needs a patch to handle the date in question. To do this we need to work out which email is causing the failure.
If you feel like 'getting you hands dirty', please do the following:

  • open the file /Users/username/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imap-backup-1.0.9/lib/email/mboxrd/message.rb and insert the line rescue puts @body at the end of line 18, i.e.:
@parsed ||= Mail.new(@body) rescue puts @body; exit
  • rerun the backup and you should see the text of the email that's causing the failure,
  • add the email headers to this issue, or even better put them in a secret gist.

Thanks, Joe

@joeyates
Copy link
Owner

Hello Martin,

were you able to pinpoint the email that was causing the problem?

@martinjuhasz
Copy link
Author

so i changed the code of the mail gem to the following:

    def parsed
      begin
        @parsed ||= Mail.new(@body)
      rescue
        puts @body
        exit
      end
    end

after starting the backup, half an hour later i got an error message like this ( yay viagra spam): https://gist.github.com/martinjuhasz/49c9a8d69581ccdd068a

@joeyates
Copy link
Owner

The malformed date is this: Sun, 26 Oct 2012 11:14:66 -0700 (with a seconds value of 66).

In cases like this, I think the only thing to be done is to log the problem and not backup the file.

@joeyates
Copy link
Owner

I've released version 1.0.10 which skips unparsable messages. You get no backup, but you get a log message indicating message id and body.

@martinjuhasz
Copy link
Author

i think thats the right decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants