awalon/MailToTelegramForwarder

Error occurred [loop]: UID command error: BAD [b'Command Argument Error. 11']

tknikita opened this issue · 10 comments

hello!

i got the following error when connect to Exchange OWA mailbox via IMAP

<2> Mail to Telegram Forwarder: Error occurred [loop]: UID command error: BAD [b'Command Argument Error. 11']. Data: b'EBCB6 UID SEARCH UID *\r\n' [/opt/rr-rps-mail-to-telegram-forwarder/mailToTelegramForwarder.py:1051 in 'main']

Hello, I have the same problem with both the mail of yahoo.es/mailfence.com

Greetings.

Google Mail:

<2> Mail to Telegram Forwarder: Error occurred [loop]: UID command error: BAD [b'Could not parse command']. Data: b'HCDI6 UID SEARCH UID *\r\n'

Google mail is not 100% imap compliant, from 0.1.2 version of forwarder I'm using modification.
It will resend email from specified folder when it is marked as unread, so you can use specific filter like:
search: (UID ${lastUID}:* UNSEEN HEADER FROM "specific@email.com")
my changes:

739c739,740
<         rv, data = self.mailbox.uid('search', '', 'UID *')
---
>         rv, data = self.mailbox.select(self.config.imap_folder)
>         rv, data = self.mailbox.uid('SEARCH', None, 'UNSEEN')
905c906,907
<             rv, data = self.mailbox.uid('search', '', search_string)
---
>             rv, data = self.mailbox.select(self.config.imap_folder)
>             rv, data = self.mailbox.uid('search', None, search_string)
942a945
>                 rv, data = self.mailbox.select(self.config.imap_folder)

Good morning, I have made the modifications but I get the same error. I don't know if I've done them right, if you can leave me your file mailToTelegramForwarder.py complete with the modifications I would appreciate it.

Mail to Telegram Forwarder: Error occurred [loop]: UID command error: BAD [b'Could not parse command']. Data: b'KCIE6 UID SEARCH UID *\r\n'

Thank you

Here you go:
downloads.zip
./m2t --config m2t.conf

Also replace <...> tags in my m2t2.conf if you use one to suffice your needs.

Needed to install python 3.9 to get whole script to work so lookup at top interpreter declaration.

Thanks

Hello, with what you sent me it works for me although it only works when there is an unread email if there is more than one does not forward them to Telegram It happens to you too? Thank you

you are right - never received more than one message in one loop so never tested this issue

Problem was when +1 messages appear, whole array was shown as UID - that was obvious error.
Now

  • every time you start, last UID is set to 1 so all unread messages will be forwarded (one or more).
  • when one or more messages are sent, they are marked as read and last UID is set back to 1 so it waits for any unread message in your 'folder'
  • you can simply mark messages as unread and they will be sent again

You can filter interesting emails by tag (folder) and additionally by any other option that IMAP query supports (look at my previous post about UNSEEN HEADER FROM).
Below is working one:
mailToTelegramForwarder.zip

definitely @lacrimal patch fixes the issue. It would be cool to merge it into awalon:master as well.