Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

POP3, C# and Response from Command?

Posted on 2014-10-03
6
Medium Priority
?
220 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 36

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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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 36

Accepted Solution

by:
ste5an earned 1500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

916 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