Missing Body text, subject and from

Giganews Newsgroups
Subject: Missing Body text, subject and from
Posted by:  slappyhack (slappyha…@gmail.com)
Date: Tue, 25 Apr 2006

First of all I want to apologize for the heated thread we had about the fonts.

The issue I am running into at this point is email from hotmail.com and some other web email systems do not contain the Body, subject or from in other words they are empty, while email from yahoo, gmail and others work fine.  I have included the method that handles the incoming mail for you to look over.  I hope you can help me out since this is in production and we have the potential to loose many emails a day do to this

Thanks in advance.

I am building a one off of this method to capture the email regardless so I can read the headers and try to send it to myself.

procedure TMailQueue.FetchMailMessagesStream();
var
  strPoolName, strUsername, strPassword, strServer, strTrackingID,
    strError, strEmailParse, strAgent, strSQL: string;
  LNumMsg, intMsgDec, i, j, x, intPort, intStatus: Integer;
  dtDate, dtHolder: Double;
  fPOP: TIdpop3;
  fMsg: TIdMessage;
  bodyS: TStringList;
  bolReturn, bolAttachments, bolDupe: Boolean;
  QueryMess: TIfxQuery;
  conn: tIfxConnection;
  TempStream: TStream;
begin
  try
    try
    //flush the buffers
      intStatus := 0;
      i := 0;
      dtHolder := 0;
      bolAttachments := false;
      fPOP := TIdpop3.Create(nil);
      fMsg := TIdMessage.Create(fPOP);
      TempStream := TMemoryStream.Create;

    //build tstrings for mail body items
      bodyS := TStringList.Create;
      bodyS.Clear;
      for i := 0 to High(arPoolMeta) do

      begin

      //populate the locals from the array of pools
        strPoolName := arPoolMeta[i].mPoolName;
        strUsername := arPoolMeta[i].mMailBox;
        //strUsername := arPoolMeta[i].mMailAccountName;
        strPassword := arPoolMeta[i].mMailAccountPassword;
        strServer := arPoolMeta[i].mPopServer;
        intPort := arPoolMeta[i].mPort;

      //set up the pop client
        fPOP.Host := trim(strServer);
        fPOP.Port := intPort;
        fPOP.Username := trim(strUsername);
        fPOP.Password := trim(strPassword);
        fPOP.Connect;
      //how many mails are there for our loop
        LNumMsg := fPOP.CheckMessages;
      //
      //copy of mail count for decrementor
        intMsgDec := LNumMsg;

        //fConnection := inttostr(LNumMsg);
        for j := 1 to LNumMsg do
        begin

        //if we have messages lets get all info from them
          //try
            //begin
          if fPOP.Retrieve(intMsgDec, fMsg) then begin // add an IDMessage
            //clear the body 01/23/2006
            BodyS.Clear;

              //rip out the carboncopy list to keep the mail server from looping.
              fMsg.CCList.Clear;

              { TODO 1 -o####### : Dupe - Check for duplicate emails from the same address and bodytext. }
              {bolDupe := isMailaDuplicate(fMsg); }

            {if bolDupe = false then
            begin}
            //go ahead and work the email else do a pop.delete and move to the next message
            //this will stop out of office loops and any other returned email loop issue.

            //save the message to a stream to pass to informix
            //position one of the stream
            TempStream.Position := 0;
            //build a stream
            fMsg.SaveToStream(TempStream);
          // bolAttachments := true;

            for x := 0 to Pred(fMsg.MessageParts.Count) do
            begin

              if fMsg.MessageParts.Items[x] is TIdAttachment then
              begin
                bolAttachments := true;
              end;

              //grab the body of the message

              if fMsg.MessageParts.Items[x] is TIdText then
              begin
                strError := TIdText(fMsg.MessageParts.Items[x]).ContentTransfer;
                BodyS.AddStrings(TIdText(fMsg.MessageParts.Items[x]).Body);

              end;

            end;

            //grab the tracking number from the subject line.
            strTrackingID := GetBetween(fmsg.Subject, '{', '}');

            {DONE -#######: Rewrite the path logic}
            if trim(fmsg.Subject) <> '' then
            begin
              if trim(BodyS.Text) <> '' then
              begin
                if trim(strTrackingID) <> '' then
                begin
                  //add the brackets back into the tracking number.
                  strTrackingID := '{' + trim(strTrackingID) + '}';

                  conn := tIfxConnection.Create(nil);
                  QueryMess := TIfxQuery.create(nil);
                  QueryMess.connection := conn;

                  //change 2/21
                  Set_IDAC_Connection(conn, fstrSystem, '', true);
                  conn.KeepConnection := false;
                  conn.Open;

                  //belongs to the agent already resent
                  intStatus := 65003;
                  //strAgent container for agent id

                  strSQL := 'select '
                    + 'netlogon '
                    + 'from imc_messages '
                    + 'where '
                    + 'currentstatus = 65004 '
                    + 'and '
                    + 'trackingnumber = :tracking';

                  QueryMess.SQL.Text := trim(strSQL);
                  QueryMess.ParamByName('tracking').AsString := trim(strTrackingID);
                  QueryMess.open;
                  QueryMess.First;

                  if not QueryMess.Eof then
                  begin
                    //grab the last known agent
                    strAgent := QueryMess.FieldValues['netlogon'];

                  end
                  else
                  begin
                  //clear out the bogus tracking number and continue as a new item
                    strTrackingID := '';
                  end;

                {DONE -######: Build resent Email logic}

                  QueryMess.free;
                  conn.free;
                end;

                ///is this a new message if so then lets process it.
                if trim(strTrackingID) = '' then
                begin

                  //test for duplicate trackingnumber
                  strTrackingID := FetchValidGUID;
                  //new Item
                  intStatus := 65000;
                  //no agent
                  strAgent := '-99999';

                end;
                strEmailParse := '';
                //pass email value to worker buffer
                strEmailParse := fmsg.From.Text;

                //rip out exchange named email headers
                if AnsiContainsStr(strEmailParse, '<') then
                begin
                  if AnsiContainsStr(strEmailParse, '>') then
                  begin
                    strEmailParse := GetBetween(fmsg.From.Text, '<', '>');
                  end;
                end;

          //write the email to the database
          //currently the attachments are ripped out
          {DONE -#######: Build Logic to handle the BLOB or attachments}
                (*bolReturn := LogMailDBAttach(strTrackingID, arPoolMeta[i].mPoolID, BodyS.Text, fMsg,
                  strEmailParse, arPoolMeta[i].mMailBox, fmsg.Subject, now,
                  arPoolMeta[i].mSmtpserver, intStatus, trim(strAgent), bolAttachments);*)

        bolReturn := LogMailDBStream(strTrackingID, arPoolMeta[i].mPoolID, BodyS.Text, fMsg,
                  strEmailParse, arPoolMeta[i].mMailBox, fmsg.Subject, now,
                  arPoolMeta[i].mSmtpserver, intStatus, trim(strAgent), bolAttachments);

                //delete the message from the server
                fPOP.Delete(intMsgDec);
                //decrement the message count
                intMsgDec := intMsgDec - 1;
              end
              else
              begin
                SendErrortoAdmin('Deleted Email TMailQueue.FetchMailMessagesStream System: ' + fstrSystem, strSQL, ' ; Body: ' + trim(BodyS.Text) + '; subject: '
              + trim(msgQueue.Subject) + '; From: ' + msgQueue.From.Text );
                fPOP.Delete(intMsgDec);
                //decrement the message count
                intMsgDec := intMsgDec - 1;
              end;
          //except
          //end;

            ///dupe
            {end
            else
              begin
                fPOP.Delete(intMsgDec);
              //decrement the message count
                intMsgDec := intMsgDec - 1;
              end; }
            ///end dupe

            end
            else
            begin
              SendErrortoAdmin('Deleted Email TMailQueue.FetchMailMessagesStream System: ' + fstrSystem, strSQL, ' ; Body: ' + trim(BodyS.Text) + '; subject: '
              + trim(msgQueue.Subject) + '; From: ' + msgQueue.From.Text );
              fPOP.Delete(intMsgDec);
              //decrement the message count
              intMsgDec := intMsgDec - 1;
            end;
          end;
        //disconnect from the server  01/23/2006
        end;
        fPOP.Disconnect;

      end;
        (*fmsg.Free;
        fPOP.Free;
        fSMTP.Free;*)

    except
      on E: Exception do begin
        SendErrortoAdmin('TMailQueue.FetchMailMessagesStream System: ' + fstrSystem, strSQL, e.Message);
        showmessage(e.Message);
      end;
    end;
  finally
    begin
      /////
      try
        QueryMess.free;
      except;
      end;

      try
        conn.free;
      except;
      end;
      /////
      try
        bodyS.Free;
      except;
      end;

      try
        fMsg.Free;
      except;
      end;

      try
        fPOP.Free;
      except;
      end;
    end;
  end;
end;

Replies