0

I am using python2.7 imaplib. When fetching an email message with the fetch command, my program becomes a wait state. Occurs only on a specific server.

I finded Waiting section in code

I guess this problem is like crlf or EOL in tcp socket communication

My develop environment Python version: 2.7 Imaplib version: 2.58 OS : ubuntu 14.04 lts

Thank

my imap command

typ, eml = self.M.fetch(num, "(RFC822)")

log(imaplib debug = 4 )

/*my request*/
38:46.59 > CCOL12 UID FETCH 2 (RFC822) 

/*server response*/
38:46.60 < * 1 FETCH (UID 2 RFC822 {1627}
38:46.60 read literal size 1627



Waiting section in code(imaplib.py)

self.file.read(size)

self.file.readline(_MAXLINE + 1)

    def open(self, host = '', port = IMAP4_PORT):
        """Setup connection to remote server on "host:port"
            (default: localhost:standard IMAP4 port).
        This connection will be used by the routines:
            read, readline, send, shutdown.
        """
        self.host = host
        self.port = port
        self.sock = socket.create_connection((host, port))
        self.file = self.sock.makefile('rb')

    def read(self, size):
        """Read 'size' bytes from remote."""
        return self.file.read(size)

    def readline(self):
        """Read line from remote."""
        line = self.file.readline(_MAXLINE + 1)
        if len(line) > _MAXLINE:
            raise self.error("got more than %d bytes" % _MAXLINE)
        return line

Waiting section in code(socket.py)

self._sock.recv(left)

def read(self, size=-1):
    ...
    data = self._sock.recv(left)



tcpflow has a value

211.235.032.125.00143-192.168.020.054.46041: * 1 FETCH (UID 2 RFC822 {1627}

PHA+67Cb7J2AIOuplOyLnOyngCDthYzsiqTtirggMjwvcD48cD48YnI+PC9wPjxpbWcgc3Jj PSJodHRwOi8vY29ycC5uaWJ0di5jby5rcjo4MC9tYWlsd3JpdGUuZHM/YWN0PXNpZ25Mb2Fk JmFtcDtkb21haW5OYW1lPW5pYnR2LmNvLmtyJmFtcDt1c2VySWR4PTQ1MiZhbXA7aW1hZ2VJ ZHg9MyI+PHA+PGJyPjwvcD4NCjxpbWcgc3JjPSdodHRwOi8vY29ycC5uaWJ0di5jby5rcjo4 MC9oaXN0b3J5U2VudC5kcz9hY3Q9Y29uZmlybSZzZW5kZXI9YzNSaGNteHZkbVU0TTBCdWFX SjBkaTVqYnk1cmNnJTNkJTNkJnJlY2VpdmVyPWRHVnpkRUJ1YVdKMGRpNWpieTVyY2clM2Ql M2Qmc3ViamVjdD02N0NiN0oyQUlPdXBsT3lMbk95bmdDRHRoWXpzaXFUdGlyZ2dNZyUzZCUz ZCZtc2dpZD1Oalk1TVRnME1qRXlPRFE0TURNeE5ESXdOZyUzZCUzZCcgd2lkdGg9JzAnIGhl aWdodD0nMCc+DQo=

------=_Part_19149_29258794.1558065910484-- ) CCOL12 OK UID FETCH completed
Community
  • 1
  • 1
  • FYI, `{1627}` means that 1627 more bytes are coming. But as you quote the response, only about 650 more bytes follow... perhaps your logging is wrong, or the way copied the data into the question? If not, if the server actually sent only about 650 bytes, then imaplib will be waiting forever for the rest of the 1627 bytes. – arnt May 22 '19 at 09:46
  • @arnt oh. thank you. I understand your comment. This is a server fault. As you say, the server sent a short byte. But I can not solve this issue. Because I am a client, not a server. I changed the command. UID FETCH 2 (RFC822) -> UID FETCH 2 BODY.PEEK[] The communication was success. And I was able to receive the EML Header. Thnks you. – Chan young May 23 '19 at 02:16

0 Answers0