Thread: Parsing e-mail headers for subject field

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Unhappy Parsing e-mail headers for subject field

    Hi,
    I'm trying to make a small e-mail client that will allow me to browse through the messages on my account and delete them if I wish. I've managed to get Winsock up and running (no easy feat, I can tell you ) and the server accepts my username and password.

    What I want to do then is to go through each message on the server, get the Subject line and add it to a list box. My code for getting the Subject line is thus:-
    Code:
    (int iStatus = current position in retrieval process (5 = receiving messages))
    (char *g_szBuffer = input buffer from recv())
    (char g_szTemp[256] = temporary string)
    (HWND g_hwndList = window handle for list box)
    (long lCurMsg = current message being received)
    (long lCount = total number of messages)
    
    if (iStatus == 5)
    {
       char *cSubjectPos, *cSubjectEnd;
       cSubjectPos = strstr(g_szBuffer, "Subject:");
       if (cSubjectPos != NULL)
       {
          cSubjectEnd = strchr(cSubjectPos, '\r')
          if (cSubjectEnd != NULL)
          {
             *cSubjectEnd = '\0';
             SendMessage(g_hwndList, LB_ADDSTRING, 0, (LPARAM)cSubjectPos+9);
             wsprintf(g_szTemp, "RETR %ld\r\n", lCurMsg);
             lCurMsg++;
             send(g_Socket, g_szTemp, strlen(g_szTemp), 0);
             if (lCurMsg > lCount)
                iStatus = 6;
          }
       }
    }
    Unfortunately, while the "Subject:" string is found, the carriage return character isn't, for some reason. Has anyone else done this or can suggest a different way of doing it?

    Or even show me what I'm doing wrong, that'd be nice

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Ah, I've seen the light that strtok() provides in this situation, so theoretically I SHOULD get the Subject line quite easily. However, I don't seem to account for lines split accross packets of data, so that causes issues.
    Is there a more reliable way of getting it?

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Are you using POP3?

    The line end is usually "\r\n".......try that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a little assistance with item class design...
    By Raigne in forum Game Programming
    Replies: 5
    Last Post: 10-22-2008, 08:55 AM
  2. Please critique and suggest improvements for parser
    By Queue in forum C Programming
    Replies: 14
    Last Post: 09-28-2006, 08:28 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM