Home > other >  Is POP3 thread safe?
Is POP3 thread safe?

Time:01-28

I use poplib to retrieve new messages from my gmail.

I do it in the following way:

server = poplib.POP3_SSL('pop.gmail.com')
# ... login with credentials

#get info about new mails (1)
emails, total_bytes = server.stat()

for i in range(emails):
    # get new mail (2)
    response = server.retr(i 1)

I was wondering what may happen if between (1) and (2) gmail mailbox receive new emails?

I tried by myself and (2) works only with messages that were actual at the moment of retrieving information about them (1) and no new messages were fetched from the server.

Is this guaranteed by POP3 protocol or not?

CodePudding user response:

Yes, POP3 locks the mailbox.

From RFC 1939:

Once the POP3 server has determined ... that the client should be given access to the
appropriate maildrop, the POP3 server then acquires an exclusive-
access lock on the maildrop, as necessary to prevent messages from
being modified or removed before the session enters the UPDATE state.

  •  Tags:  
  • Related