473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Treat a POP3 mailbox like a queue

I would like to monitor a POP3 mailbox with multiple clients. However, I want
to ensure that each message is processed by only one client. In essence, I
would like to treat a POP3 mailbox like a queue.

From what I've read thus far, atomic message access (if this is the right term)
isn't a native feature of the POP3 protocol. Am I mistaken?

My approach thus far, is to have one thread connect to the mailbox periodically,
look for new messages, add each message's ID to a queue (MSMQ or SQS), then mark
the message as read. A pool of threads would monitor the queue, get the next
message ID, 'process' the message, then delete it. I would probably segment
these activities into two windows services.

Does this seem like a reasonable pattern? Is there another, similar pattern
that I should consider?

Thanks for your time,

Craig Buchanan
Nov 7 '08 #1
5 1445
"Craig Buchanan" <na**@company.comwrote in message
news:eY****************@TK2MSFTNGP02.phx.gbl...
>I would like to monitor a POP3 mailbox with multiple clients.
Let's get this out of the way at the start: does the mail server absolutely
not provide IMAP access?
Nov 7 '08 #2
Jeff Johnson wrote:
"Craig Buchanan" <na**@company.comwrote in message
news:eY****************@TK2MSFTNGP02.phx.gbl...
>I would like to monitor a POP3 mailbox with multiple clients.

Let's get this out of the way at the start: does the mail server absolutely
not provide IMAP access?

At this point, the server is just POP3. If IMAP offers more flexibility, I
would consider migrating.

One approach occurred to my during lunch. I could use multiple threads in
combination w/ the auto-increment message id (which is different from the
message's unique id). I create a method that synchLocks a counter that starts
at 1 and is incremented by one during each call. each thread gets the Id, then
attempts to retrieve that message from the server. i would need to catch errors
that result from messages that are marked for deletion and when the ID has
exceeded the last message on the server. i would need to create a mechanism to
reset the counter to 1 when a POP3 session is closed.

Thoughts?
Nov 7 '08 #3
Mike-

Thanks for the reply.

So, there isn't another way to enter the UPDATE state w/o quitting? This would
be quite useful.

If I try to get a message using its ID (the auto-increment value), and it has
been marked for deletion, what happens? I'm assuming that it returns -ERR plus
a message. At what point do auto-increment values get reset?

As I recall, NNTP has a method to return the first and last message ids (without
getting all of the messages). I don't see anything like that in 1939. Is this
correct?

Thanks.

Craig

Michael B. Trausch wrote:
On Fri, 07 Nov 2008 10:51:00 -0600
Craig Buchanan <na**@company.comwrote:
>I would like to monitor a POP3 mailbox with multiple clients.
However, I want to ensure that each message is processed by only one
client. In essence, I would like to treat a POP3 mailbox like a
queue.

From what I've read thus far, atomic message access (if this is the
right term) isn't a native feature of the POP3 protocol. Am I
mistaken?

RFC 1939 doesn't provide any assurances that message access be atomic
in the sense I think you mean. For example, if you connect to a POP3
server and get a message list with message IDs 1 through 10, and delete
messages 2, 3, and 4, those messages still technically exist until you
issue the "QUIT" command on the server. The POP3 server then updates
the mailbox and removes the messages. This is because while in the
TRANSACTION state, the "RSET" command may be issued which effectively
undeletes the messages and the server only enters the UPDATE state when
QUIT is issued (in the TRANSACTION state).
>My approach thus far, is to have one thread connect to the mailbox
periodically, look for new messages, add each message's ID to a queue
(MSMQ or SQS), then mark the message as read. A pool of threads
would monitor the queue, get the next message ID, 'process' the
message, then delete it. I would probably segment these activities
into two windows services.

Does this seem like a reasonable pattern? Is there another, similar
pattern that I should consider?

This seems reasonable assuming that it is only a single thread
accessing the mailbox and you're using unique identifiers as opposed to
simple ID numbers. Though, keep in mind that unique IDs are not even
required to be unique; the standard permits identical IDs for exactly
identical messages (e.g., a mailserver *could* use a GUID for unique
identifer, or it could use an MD5 hash of the message, so long as
either is transformed into the format required by the RFC.

A better solution, of course, if you must accept email messages to
formulate the queue would be to have your software implement a
mini-SMTP server and accept the messages directly, if this is at all
feasible. This way, you simply take the messages and work with them
directly. When you receive a message, then, you can just put it in the
queue directly. Saving state would be up to you, but you could simply
serialize the queue and save it to disk after every update to the
queue. Or you could use some sort of on-disk spool to represent the
queue's saved state, or whatever. Point being that you can at least
bring the control of the queue (and handling of it) entirely within
your application. You can also handle duplicate queue requests
directly instead of trying to detect them on the server, if duplicates
matter at all in your application.

--- Mike
Nov 7 '08 #4
"Craig Buchanan" <na**@company.comwrote in message
news:uK**************@TK2MSFTNGP04.phx.gbl...
>>I would like to monitor a POP3 mailbox with multiple clients.

Let's get this out of the way at the start: does the mail server
absolutely not provide IMAP access?
At this point, the server is just POP3. If IMAP offers more flexibility,
I would consider migrating.
IMAP offers considerably more flexibility, but of course it's more
complicated to work with. I just happen to know that there's a "seen" flag
for messages under IMAP, so this might do what you want. Plus I believe
every message gets a unique ID.
Nov 7 '08 #5
thanks for the response. i will give the idea of a mini-stmp further consideration.
idempotent.
good one.

Thanks again.

Craig

Michael B. Trausch wrote:
On Fri, 07 Nov 2008 14:12:46 -0600
Craig Buchanan <na**@company.comwrote:
>Thanks for the reply.

So, there isn't another way to enter the UPDATE state w/o quitting?
This would be quite useful.

If I try to get a message using its ID (the auto-increment value),
and it has been marked for deletion, what happens? I'm assuming that
it returns -ERR plus a message. At what point do auto-increment
values get reset?

Yes, RFC 1939, page 8, states that DELE takes a message number, "which
may NOT refer to a message marked as deleted". On page 9, it is found
that:

The POP3 server marks the message as deleted. Any future
reference to the message-number associated with the message
in a POP3 command generates an error. The POP3 server does
not actually delete the message until the POP3 session
enters the UPDATE state.

On page 10, regarding the UPDATE state:

When the client issues the QUIT command from the TRANSACTION state,
the POP3 session enters the UPDATE state. (Note that if the client
issues the QUIT command from the AUTHORIZATION state, the POP3
session terminates but does NOT enter the UPDATE state.)

If a session terminates for some reason other than a client-issued
QUIT command, the POP3 session does NOT enter the UPDATE state and
MUST not remove any messages from the maildrop.

This means that if your TCP connection to the POP3 server is severed,
you will have to remember the state on your own, or reprocess the
messages on the server. This would not be a good thing, if your
operations which you're queuing are not idempotent.
>As I recall, NNTP has a method to return the first and last message
ids (without getting all of the messages). I don't see anything like
that in 1939. Is this correct?

I don't quite know what you mean here. Message IDs are enumerated by
the server when you reconnect to it. For example, if you connect to a
POP3 server and it has 10 messages, it will number them 1 through 10.
Delete 2, 3, and 4, and QUIT, and reconnect immediately and you have 1
through 7. The numbers will be reused.

If you want identification that is unique and persists across sessions,
you're looking for the IDs which are provided by the UIDL command. Do
note that the UIDL command is optional per RFC 1939.

I'd recommend reading RFC 1939 in its entirety. RFCs are somewhat
terse, but usually reading them a second time a few hours later helps
to "fill in the blanks", particularly with the larger RFCs.

I also would re-echo my recommendation that I gave in my previous
message, to run a mini-SMTP server within your code base and accept
messages that way, so that you're not relying on POP3 to help you out.
I think that using POP3 (or anything external to you that isn't
absolutely ensured to keep state the way you expect) will in the long
run not work out very well...

--- Mike
Nov 7 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3101
by: Alexander Franksmann | last post by:
Hello, I'm going to write a anti-spam-program based on a Whitelist. "If the mail sender is found in the database, my program should move the mail into another mailbox" The mailserver fetched the...
4
3718
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it...
1
5941
by: Lev Altshuler | last post by:
Hi, I am trying to count email messages in the mailbox and read their headers. In case that there are some messages on the POP3 server and they haven't yet got to the Inbox, I get a number of...
4
2707
by: Ron Vecchi | last post by:
I a runnning w2k3 pop3 mail server that came with iis6. I would like to write an application that progammtically creates the new mailboxes in an already established mail domain. Does anyone know...
1
5971
by: Ajeet YS | last post by:
Hello, Well, I don't know if this is the right forum to post this query, but I didn't find any other suitable one. I am developing a program to access mails from a pop3 server's mailbox. For...
2
2817
by: Mike Brearley | last post by:
I need to write a script that will check a catch-all mailbox (pop3) and send a non delivery report back to the sender of the email. Background info: I have a domain hosted on a site that offers...
0
1281
by: Gabe Matteson | last post by:
Good morning, The point of this posting is to find out a way to insert downloaded email into your exchange mailbox. 1. I know how to download pop3 mail using asp to a web page. 2. i would like to...
1
10044
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
4
4159
by: bill | last post by:
I am in preliminary design of a contact management program. The user would like to use his current mail server (POP3 - remote). I have done some reading on the IMAP functions but am unclear if...
5
2656
by: Craig Buchanan | last post by:
I would like to monitor a POP3 mailbox with multiple clients. However, I want to ensure that each message is processed by only one client. In essence, I would like to treat a POP3 mailbox like a...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.