IMAP BAD [CLIENTBUG] Invalid tag - imap

I want send IMAP command so that I can receive IMAP response.
So a short code that easy for undertanding but save space to prevent type all code and faster for the Overflow reader:
SSL_write("a0001 login user pass")
SSL_read = "* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
a0001 OK mrtallpuducherry#gmail.com authenticated (Success)
OK, now everything ok, but here is where problem that is small start:
SSL_write("a0002 select inbox\r\n\r\n")
SSL_read = * BAD [CLIENTBUG] Invalid tag
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $NotPhishing)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $NotPhishing \*)] Flags permitted.
* OK [UIDVALIDITY 1] UIDs valid.
* 7958 EXISTS
* 0 RECENT
* OK [UIDNEXT 22979] Predicted next UID.
* OK [HIGHESTMODSEQ 2553479]
a0002 OK [READ-WRITE] inbox selected. (Success)
Any time after login when I send the IMAP command to get the IMAP response, always the first thing I receive is
* BAD [CLIENTBUG] Invalid tag
After it tell me BAD it then give me proper response and tell me (Success).
Is very confusing to me because I give correct tag. I use OpenSSL on linux platform.
This example with gmail server but happen on all IMAP server tested. Login is perfect and everything else start with "Invalid tag" then give me correct response.
Do you know what I do wrong and how to prevent this? Thanks you very much. My kindest regard.

The problem is here:
SSL_write("a0002 select inbox\r\n\r\n")
Only write one CRLF:
SSL_write("a0002 select inbox\r\n")
You've unintentionally sent two commands. One is the command you wanted, one was the empty command, which has no (an invalid) tag.

Related

`Unsafe redirect to "https://${ip}/signin"` while running rails application

I'm trying to analyze log from my rails applications I sometimes see hits from random IP addresses that look like this:
-------------------------------
Request:
-------------------------------
* URL : https://${ip}/
* HTTP Method: GET
* IP address : 162.62.191.231
* Parameters : {"controller"=>"runner", "action"=>"index"}
* Timestamp : 2022-08-17 18:28:07 +0300
* Server : b82b789929df
* Rails root : /root/my_app
* Process: 270
Those are not some replacement to hide IP from you, it seems like literally request with https://${ip}/ value
But not sure from where it's coming, probably some guys are testing my site for some vulnerability, but I cannot detect which.
https://${ip}/ is a really bad string to google it
And especially I cannot understand how to simulate the same request with curl or wget to see if it really safe
Fact is that it couldn't get to your server unless it was a correct hostname/ip-address, so that URL is not what's being requested. My guess here is that this is some local monitoring or health-check, is this on AWS?

IMAP error: mailbox name contains server's hierarchy delimiter

I am trying to configure isync to fetch data from home.pl IMAP server. I have the simplest possible configuration file:
# ~/.mbsyncrc
IMAPStore store
Host host
Port 993
User kosciej#host.com.pl
PassCmd "pass poczta.home.pl/kosciej"
SSLType IMAPS
MaildirStore host-local
Path ~/.mail/host/
Channel host-inbox
Master :host-remote:"INBOX"
Slave :host-local:inbox
However it produces the error IMAP error: mailbox name inbox contains server's hierarchy delimiter. I connected to the server with openssl and found there is INBOX mailbox with . as delimiter.
a list "" *
* LIST (\HasNoChildren) "." "INBOX"
...
I managed to fix the problem with Pattern
Master :host-remote:
Slave :host-local:
Patterns inbox
But cannot understand what the error was about, it looks like "INBOX" has . somewhere?
Could anyone explain why the first version doesn't work?

IMAP and Gmail Labels

I'm trying to figure out how to add GMail labels to my app. I'm using Mailcore that doesn't support it so I want to add them my self. I've researched a bit and found this:
a010 FETCH 1:4 (X-GM-LABELS)
* 1 FETCH (X-GM-LABELS (\Inbox \Sent Important "Muy Importante"))
* 2 FETCH (X-GM-LABELS (foo))
* 3 FETCH (X-GM-LABELS ())
* 4 FETCH (X-GM-LABELS (\Drafts))
a010 OK FETCH (Success)
https://developers.google.com/google-apps/gmail/imap_extensions#x-gm-labels
What languge is this? Is that an API? How do I access it?
Thanks
It's the IMAP protocol, defined here: http://www.ietf.org/rfc/rfc1730.txt. You can connect to an IMAP server via telnet (usually tcp port 443) and run that fetch command.
Here's an example of how to use telnet to connet to an IMAP server and run commands, such as FETCH, manually.
http://networking.ringofsaturn.com/Protocols/imap.php

Yahoo IMAP UID+ COPYUID broken?

It seems the COPYUID functionality in Yahoo's IMAP UID+ is not at all working. e.g. our task that moves messages receives the trace:
S: C32 OK [COPYUID 1348693428 122572 122552] COPY completed
We log into the box and verify uidvalidity:
S: * OK [UIDVALIDITY 1348693428] UIDs valid
However the fetch fails:
C: C6 UID FETCH 122552 (BODY.PEEK[] UID)
S: C6 OK UID FETCH completed
I'm wondering if anyone has experienced similar frustrations over Yahoo UID+, if there is a workaround, I have an error in my client etc.
Furthermore I am testing this on my personal account and messages are not modified after being copied.
Fwiw several weeks of development on this later I can confidently say yes, it's just flat-out broken and should not be used.

string reading problem through IMAP

I am working on a IMAP, so just reading the body (body[header.fields (DATE FROM SUBJECT)]) I am passing this command.
But problem is like there some time my string return extra stuff excetp from my original string.
and some times I had getting limited part of the string means half part of the body.
so whenever I am passing second command it will accept as a first command and return result as the
first command pending resul.;
so the my concern is that I am not able to retrive proper data as of the part of the body.
as per my knowladge I think it's happen due to the internet datapacket tresfersize, but apart from this look at outlook or any other mail manager will work properly so what this is the mechanisam for
this data retriving.
or anything else to do fo my coding.....
Thanks..
Posting a sample response from the IMAP server that contains the "extra stuff" would help.
The problem you are most likely facing is with untagged server responses.
Heres what RFC3501 says:
Status responses can be tagged or untagged. Tagged status responses indicate the completion result (OK, NO, or BAD status) of a client command, and have a tag matching the command:
C: a002 NOOP
S: a002 OK NOOP completed
Some status responses, and all server data, are untagged. An
untagged response is indicated by the token "*" instead of a tag.
C: a047 NOOP
S: * 22 EXPUNGE
S: * 23 EXISTS
S: * 3 RECENT
S: * 14 FETCH (FLAGS (\Seen \Deleted))
S: a047 OK NOOP completed
So you need to distinguish between those 2 response types.
Please remember that checking if every received line starts from '*' character is not enough, as your email message may also have lines starting from star character:
C: a004 fetch 12 body[header]
S: * 12 FETCH (RFC822 {342}
S: Date: Wed, 17 Jul 1996 02:23:25 -0700 (PDT)
S: From: Terry Gray <gray#cac.washington.edu>
S: Subject: IMAP4rev1 WG mtg summary and minutes
S: MIME-Version: 1.0
S:
S: * This is email body containing start char
S: )
S: a004 OK FETCH completed
{342} is the exact number of bytes you are supposed to read.
The bottom line is don't reinvent the wheel use existing library.
You can check out mine IMAP component (not free).

Resources