0

几年前,我写了一个扔掉的程序,只用过一次就被删除了。从那以后,我的客户每天都在使用它。

它的目的是拉下“票”邮件并从正文中读取一个 Ack + 号码。可能有几个并且全部被读入一个 Tstringlist 来处理。

昨天,他们从 RackSpace 切换到了 Amazon Work Mail。我的身份验证工作正常,但我的程序看不到邮件正文。它正确地获得了计数,我在调试器下看到了标题,但它也没有被复制到 Memo1。

我已经通过亚马逊的网络界面验证了邮件并查看了主题和正文。他们都在那里。

邮件已被多次删除和恢复(如果这可能是问题)。这对 RackSpace 来说从来都不是问题。

RackSpace 没有使用加密,但亚马逊确实使用了 TLS。

这是在亚马逊之前奏效的方法——

谁能明白为什么我仍然可以看到邮件计数但没有尸体?

主要流程

procedure TForm1.GetGmailBodyTextParts;
var
  MsgIndex, i: integer;
  MsgObject: TIdMessage;
  TheUID: string;
  fatalError: boolean;
  s, sSerialNum, sAck: string;
  msgStatus: string;
  failed: boolean;
  ToDelete: integer;
  Confirmed: array of integer;
  iTotalMsgs: integer;
  ackedSuccess: integer;
  totalInList: integer;
  ackList: TStringList;
  timeStart, timeStop: TDateTime;
  elapsedTime: integer;
  mailPerTime: double;
const
  FILE_EXT = '.TXT';
begin
  ToDelete := 0;
  ackedSuccess := 0;
  fatalError := false;
  Memo1.Clear;
  Memo2.Clear;
  IMAPClient.Disconnect(true);
  IMAPClient.Connect;
  timeStart := GetTime;
  try
    ackList := TStringList.Create;
    ackList.Duplicates := dupIgnore;
    ackList.Sorted := true;
    if (IMAPClient.SelectMailBox(MailBoxName) = true) then
    begin
      iTotalMsgs := IMAPClient.MailBox.TotalMsgs;
      ProgressBar1.Max := iTotalMsgs;
      StatusBar1.Panels[5].Text := IntToStr(iTotalMsgs);
      for MsgIndex := 1 to IMAPClient.MailBox.TotalMsgs do
      begin

        MsgObject := TIdMessage.Create(nil);
        failed := false;
        ToDelete := 0;
        try

          If not(IMAPClient.Retrieve(MsgIndex, MsgObject)) then continue;
          MsgObject.Headers.ConvertToStdValues(Memo1.Lines);

          if mfDeleted in MsgObject.Flags then
          begin
            dec(iTotalMsgs);
            StatusBar1.Panels[5].Text := IntToStr(iTotalMsgs);

            FreeAndNil(MsgObject);
            continue; // flagged for delete
          end;

          StatusBar1.Panels[3].Text := IntToStr(MsgIndex);
          StatusBar1.Refresh;
          application.ProcessMessages;

          SetLength(Confirmed, Succ(ToDelete));
          Confirmed[ToDelete] := MsgIndex;
          Inc(ToDelete);

          if not MsgObject.IsBodyEmpty then
          begin
            ackList.Clear;
            ackList.AddStrings(RemoveDups(MsgObject.Body));

            Memo2.Lines.AddStrings(ackList);
            totalInList := ackList.Count;

            for i := 0 to totalInList - 1 do
            begin
              s := Trim(ackList[i]);
              sSerialNum := Trim(copy(s, 0, pos(#44, s) - 2));
              sAck := Trim(copy(s, pos(#44, s) + 2, maxChar));
              try
                ackedSuccess := 0;
                updRespLog.Parameters.ParamByName('ack').Value := sAck;
                updRespLog.Parameters.ParamByName('serialNo').Value :=
                  sSerialNum;
                ackedSuccess := updRespLog.ExecSQL;
                assert(ackedSuccess > 0, 'Cannot find ' + sSerialNum +
                  ' to Ack - missing ');
                if ackedSuccess > 0 then
                begin
                  delRespActWait.Parameters.ParamByName('serialNo').Value :=
                    sSerialNum;
                  delRespActWait.ExecSQL;
                end;
              except
                on e: exception do
                begin

                  LogResult.LogType := ltMissing;
                  LogResult.Status := 'Missing: ' + sSerialNum;
                  WriteLog(LogResult);
                  Memo2.Lines.add(LogResult.ExcepMsg);

                  ackedSuccess := 1;

                end;
              end; // except

            end; // for i := 0 to ListBox1.Count - 1 do
            LogResult.MethodName := 'Processing Mail, saving copy';
            LogResult.DataStream := 'serialNumbers: ' + ackList.CommaText;
            LogResult.LogType := ltInfo;
            WriteLog(LogResult);
            Memo2.Lines.add('Processed ' + sSerialNum + ' Ack');
            Memo2.Lines.add('Processed ' + IntToStr(i) + ' of ' +
              IntToStr(totalInList));
            MsgObject.Body.SaveToFile(bodyTextDir + '\' + callCenter +
              FormatDateTime('yyyy-mm-dd hh-mm-ss', MsgObject.Date) + FILE_EXT);

          end
          else
          begin

            LogResult.MethodName := 'Processing Mail';
            LogResult.Status := 'mail body empty-nothing to do!!';
            LogResult.DataStream := 'Mail Timestamp: ' +
              DateTimeToStr(MsgObject.Date);
            LogResult.LogType := ltInfo;
            WriteLog(LogResult);
          end;

          if SafeStop then
            exit;
        finally
          IMAPClient.UIDStoreFlags(TheUID, sdAdd, MsgObject.Flags + [mfDeleted]);
          MsgObject.Free;
        end;
        application.ProcessMessages;
        ProgressBar1.StepIt;
      end; // 1 to IMAPClient.MailBox.TotalMsgs
    end;
  finally
    IMAPClient.Disconnect;
    timeStop := GetTime;

    elapsedTime := secondsBetween(timeStart, timeStop);
    mailPerTime := totalInList / elapsedTime;
    Memo2.Lines.add('Total Mail Processed ' + IntToStr(totalInList));
    Memo2.Lines.add('Mail per second ' + floatToStr(mailPerTime));

    ackList.Free;
    btnHotStop.Enabled := false;
    btnDeleteClick(nil);
    StatusBar1.Panels[7].Text := 'Stopped';
    Memo1.Clear;
    if not SafeStop then
      Memo1.Lines.add
        ('All Acks have been Attacked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    else
      Memo1.Lines.add('Taking a breather....')
  end;
end;
4

0 回答 0