Solved

POP3, C# and Response from Command?

Posted on 2014-10-03
6
198 Views
Last Modified: 2014-10-17
Hi,

I have an interesting dilemma that started a little while ago.

I have an exchange mailbox that I will access with OWA from a browser.

However, I have an application that will access the mailbox as well and perform most of the activity. That is where the strangeness is happening. Generally, there will be like 600 emails a day that will go into the Inbox and the application will process. As part of the process it will retrieve the necessary message and process it then issue the command to delete the message (DELE {Whatever the number of the message}). Again, for the large majority of the time it processes just fine. Yet, I will randomly get a message in it that just causes havoc. When that message in as in the Inbox more "normal" messages will come in BUT it will never delete those message. As a result, the inbox will build and build.

Here is a little snippet of the code:

try {
        pop3Stream.Write(commandBytes, 0, commandBytes.Length);
        if (isDebug) {
          isDebug=false;
          throw new IOException("Test", new SocketException(10053));
        }
      } catch (IOException ex) {
        //Unable to write data to the transport connection. Check if reconnection should be tried
        isSupressThrow = {execute reconnect};
        if (!isSupressThrow) {
          throw;
        }
      }
      pop3Stream.Flush();

      //read response from server
      response = null;
      try {
        response = pop3StreamReader.ReadLine();
      }catch (IOException ex) {
        //Unable to write data to the transport connection. Check if reconnection should be tried
        isSupressThrow = {execute reconnect}
        if (isSupressThrow) {
          //wait for response one more time
          response = pop3StreamReader.ReadLine();
        } else {
          throw;
        }
      }
      if (response==null) {
        throw new Pop3Exception("Server "+ popServer + " has not responded, timeout has occured.");
      }

Open in new window


Now, the problem is in that situation with the email that doesn't delete is that the
response

Open in new window

is "" there is would "normally" get like an "+OK".  All subsequent emails that hit this code get some other cryptic type message that doesn't look like a response from a command.

I need to take that one email that is causing everything out of the mailbox by moving it and only then will everything go back to processing normally.

Any ideas on this? Should I loop on the
response = pop3StreamReader.ReadLine();

Open in new window

line while the response is "" for a certain period of time?

Any thoughts or suggestions on this?

Any information would be greatly appreciated.
0
Comment
Question by:davism
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 40361217
not a POP expert, but there is also an Exchange WebServices API that works directly and well for me.
0
 
LVL 1

Author Comment

by:davism
ID: 40361222
I cannot change the code or anything nor does it make any since. Especially when this has been running fine for almost 2 years.

Any other thoughts or ideas related to this?
0
 
LVL 32

Expert Comment

by:ste5an
ID: 40361271
Just it was running for two years, doesn't mean that it was okay.

But I would assume that the problem may be your pop3Stream. How is it implemented?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:davism
ID: 40361697
I will have to provide the info when I get connect to my work again. Once I do I will post the response to your question.

But help me understand, if it's been running fine and has processed over 100,000 emails with no problem but now all of a sudden starts (began on 9/11 actually) and is randomly  encountering an issue how would that constitute not being ok? The machine hasn't been patched so nothing has changed; it has been rebooted on normal quarterly schedules.

I know we have another test environment with a mailbox specific to test. It runs the same program just from a different machine accessing the same mailbox server. I have forwarded the culprit email to that test mailbox and the test server application (which is the same code) deleted it without a problem. But I would imagine the forwarding changed the header and all. How can I get that same email in a different mailbox? That way I could test more to try and isolate the problem with that email or emails like that.
0
 
LVL 32

Accepted Solution

by:
ste5an earned 500 total points
ID: 40362084
The behaviour you've described sounds like the pop3stream is not capturing the Ok from the server. This can be a race condition. This maybe for example by a different bandwidth. My first approach would using a network sniffer to check whether the ok is sent and the timing looks like.
0
 
LVL 1

Author Closing Comment

by:davism
ID: 40387825
The result was that it had to be attempted again. The first read didn't capture the "+OK" the second attempt did.

Thanks for the info and responding. It's very much appreciated.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now