nylas / sync-engine

:incoming_envelope: IMAP/SMTP sync system with modern APIs
https://nylas.com/docs/platform
GNU Affero General Public License v3.0
3.5k stars 354 forks source link

Account has no detected sent folder; not saving message #300

Open cirk0 opened 8 years ago

cirk0 commented 8 years ago

Sync-engine fails to detect IMAP folders when using with self hosted mail servers.

I don't really understand because i can see create_folder function in the code but it's not used when authorizing new accounts. A freshly created account has only an INBOX folder and nothing else and other folders are created normally by the email client.

Adding the mail server details to generic accounts with folder_mapping doesn't solve the issue.

Even after manually creating those folders, sync-engine is just unable to detect the newly created folders. The best way to reproduce it, is to create a new e-mail account on a mail server and send an e-mail via sync engine api. The e-mail will be deleted and not saved in sent folder.

khamidou commented 8 years ago

Oh, this shouldn't be happening! Can you give us more details about your email server: which IMAP server are you using, the list of folders, your locale, etc.? It would be super helpful to debug this!

Thanks,

k

cirk0 commented 8 years ago

E-mail server: hMailserver When an account is created, only one folder is added: 'INBOX'

Basically, this only occurs if the e-mail is authorized via sync-engine without creating the standard folders like "sent,trash,archive,junk" on the e-mail server.

If the folders are created prior authorization, sync-engine can detect and use them.

Sync-engine can't detect folders if those are created after authorization. The only way to make sync-engine recognise the folders is to re-authorize the account. Although re-authorization doesn't modify an existing account but duplicates it with new id so I normally delete those accounts and authorize them again to avoid having dead records in the database.

khamidou commented 8 years ago

Ah. The sync-engine doesn't create folders if you don't ask it to. However, it should be able to pick up new folders automatically. What happen if you let the sync engine run for 10+ minutes --- do the new folders get synced?

cirk0 commented 8 years ago

Even after 24 hours, new folder won't get synced.

If i create new folder via /folders/ endpoint it gets synced and is used for sent messages.

When creating folders directly in the email server admin interface, /folders/ endpoint shows the folder is there with a unique id, but still not used when moving/saving/sending messages around.

cirk0 commented 8 years ago

Actually I could overcome this issue by creating folders via /folders/ endpoint.

Many older accounts that worked before (~2 months ago) had folder syncing issues as well but after flushing everything from redis, all the accounts got resynced and they started working again. I assume I should perform redis flush after each upgrade.

cirk0 commented 8 years ago

These errors came up time to time only for accounts with folder syncing problems.

[INFO] {"level": "info", "timestamp": "2016-05-09T13:56:24.537985Z", "module": "inbox.transactions.actions:99", "greenlet_id": 140570346675888, "msg": "save_sent_email", "event": "delegating action", "action_id": 249}

[ERROR] {"account_id": 23, "timestamp": "2016-05-09T13:56:24.552154Z", "module": "inbox.crispin:326", "record_id": 821, "greenlet_id": 140570336190128, "event": "IMAPClient error selecting folder. May be deleted", "level": "error", "extra_args": {}, "action_log_id": 249, "error": "command: SELECT => You will be disconnected because of timeout (30 minutes).", "action": "save_sent_email"}

[INFO] {"account_id": 23, "timestamp": "2016-05-09T13:56:24.552427Z", "module": "inbox.crispin:171", "record_id": 821, "greenlet_id": 140570336190128, "event": "IMAP connection error; discarding connection", "exception": "Traceback (most recent call last):\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/inbox/crispin.py\", line 164, in get\n    yield client\n\t  File \"/usr/share/python/inbox-sync/lib/python2.7/site-packages/inbox/actions/backends/generic.py\", line 252, in remote_save_sent\n    crispin_client.select_folder(folder_name, uidvalidity_cb)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/inbox/crispin.py\", line 313, in select_folder\n    folder, readonly=self.readonly)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/imapclient/imapclient.py\", line 481, in select_folder\n    self._command_and_check('select', self._normalise_folder(folder), readonly)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/imapclient/imapclient.py\", line 1180, in _command_and_check\n    typ, data = meth(*args)\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 661, in select\n    typ, dat = self._simple_command(name, mailbox)\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 1087, in _simple_command\n    return self._command_complete(name, self._command(name, *args))\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 911, in _command_complete\n    raise self.abort('command: %s => %s' % (name, val))\n\tabort: command: SELECT => You will be disconnected because of timeout (30 minutes).\n", "level": "info", "extra_args": {}, "action_log_id": 249, "action": "save_sent_email"}

[ERROR] {"exception": "Traceback (most recent call last):\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/inbox/transactions/actions.py\", line 182, in _run\n    self.func(self.account_id, self.record_id)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/inbox/actions/base.py\", line 155, in save_sent_email\n    remote_save_sent(account_id, message_id)\n\t  File \"/usr/share/python/inbox-sync/lib/python2.7/site-packages/inbox/actions/backends/generic.py\", line 252, in remote_save_sent\n    crispin_client.select_folder(folder_name, uidvalidity_cb)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/inbox/crispin.py\", line 313, in select_folder\n    folder, readonly=self.readonly)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/imapclient/imapclient.py\", line 481, in select_folder\n    self._command_and_check('select', self._normalise_folder(folder), readonly)\n\t  File \"/usr/share/python/inbox-sync/local/lib/python2.7/site-packages/imapclient/imapclient.py\", line 1180, in _command_and_check\n    typ, data = meth(*args)\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 661, in select\n    typ, dat = self._simple_command(name, mailbox)\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 1087, in _simple_command\n    return self._command_complete(name, self._command(name, *args))\n\t  File \"/usr/lib/python2.7/imaplib.py\", line 911, in _command_complete\n    raise self.abort('command: %s => %s' % (name, val))\n\tabort: command: SELECT => You will be disconnected because of timeout (30 minutes).\n", "account_id": 23, "level": "error", "timestamp": "2016-05-09T13:56:24.552740Z", "greenlet_id": 140570336190128, "module": "inbox.transactions.actions:200", "extra_args": {}, "action": "save_sent_email", "action_log_id": 249, "provider": "imap", "record_id": 821, "event": "Uncaught error"}
c0fe commented 8 years ago

I had the same problems as cirk0. I had one IMAP account using HostGator shared hosting. Having added an additional account it caused that other account to pull older emails from the first account even though both are completely different.

bengotow commented 8 years ago

Hey @c0fe - are you hosting the sync engine yourself? The issue you described is a little unrelated to this thread, but it can happen if your config.json in N1 doesn't set the API tokens for the two accounts to their two respective account IDs. (I.e. If you copy paste the token to make one for the second account but don't change it, N1 will sync account A mail and save it as account B mail.)

c0fe commented 8 years ago

No never installed it or hosted it. I am not really making sense of the sync engine or its purpose.