⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fnewaccountwizard.pas

📁 siMail, siMail, siMail, siMail
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          POP3UserName := Trim(txtLoginUser1.Text);

          if chkSamePwd.Checked and not chkSamePwd.Checked then begin
            SMTPUserName := '';
            SMTPPassword := '';
          end
          else begin
            SMTPUserName := txtLoginUser2.Text;
            SMTPPassword := txtLoginPwd2.Text;
          end;

          SMTPPort := StrToInt(frmNewAccServerProperties.txtSMTPPort.Text);
          SMTPServer := txtOutGoing.Text;
          SMTPTimeout := StrToInt(frmNewAccServerProperties.txtSMTPTimeout.Text);
          SMTPAuthType := TSMTPAuthType(cmboxSmtpAuth.ItemIndex);
          SMTPSamePwdAsForIncoming := chkSamePwd.Checked;
        end
      end;
    end;
  end;
end;

procedure TfrmNewAccountWizard.findServerSettings;
var node: IXMLNode;
var nodeLst: IXMLNodeList;
var i: Integer;
var tmpStr: String;
begin

  tmpStr := LowerCase(Trim(txtEmail.Text));
  tmpStr := RightStr(tmpStr, Length(tmpStr) - Pos('@', tmpStr));

  nodeLst := FilterNodes(serverSett.DocumentElement, 'server');
  for i := 0 to nodeLst.Length - 1 do begin

    node := nodeLst.Item[i];
    if SameText(FindNode(node,'mailAddressEnd').Text, tmpStr) then begin
      //we have correct address write data to txtBoxes and exit
      txtIncoming.Text := FindNode(node,'incomingServer').Text;
      txtOutgoing.Text := FindNode(node,'outgoingServer').Text;
      break;
    end;
  end;
end;

procedure TfrmNewAccountWizard.prepareControls;
begin
  txtProfile.Text := '';
  txtPwd.Text := '';
  txtAccountName1.Text := '';
  //gettext: default account path
  txtAccountPath.Text := _('<Default>');
  txtAccountName2.Text := '';
  txtYourName.Text := '';
  txtOrganization.Text := '';
  txtEmail.Text := '';
  txtReplyEmail.Text := '';
  txtLoginUser1.Text := '';
  txtLoginPwd1.Text := '';
  txtIncoming.Text := '';
  txtOutgoing.Text := '';
  txtLoginUser2.Text := '';
  txtLoginPwd2.Text := '';
end;

function TfrmNewAccountWizard.validateEmail(str: String): Boolean;
begin
  if StrPos(Pchar(str), '@') = nil then begin
    MessageDlg(_('Please enter valid e-mail address to e-mail address field.'),
      mtError, [mbOK], 0);
    Result := False;
  end
  else
    Result := True;
end;

procedure TfrmNewAccountWizard.FormDestroy(Sender: TObject);
begin
  serverSett := nil;
end;

procedure TfrmNewAccountWizard.FormCreate(Sender: TObject);
begin
  popAndSmtpLoaded := False;

  //form: New account wizard, control: Step 5 - &Authentication type:
  cmboxSmtpAuth.Items.Text := _('None' + #13#10 +
                          'Automatic');
end;

procedure TfrmNewAccountWizard.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if frmMailbox.Profiles.Count > 0 then CanClose := True
  else begin
    if MessageDlg(_('At least one account must be created.' +#13#10 +'Are you sure you want to close si.Mail?'), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
      Application.Terminate
    else
      CanClose := False;
  end;
end;

procedure TfrmNewAccountWizard.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
  if msg.CharCode = 27 then begin
    Self.Close;
    Handled := True;
  end;
end;

function TfrmNewAccountWizard.CheckAccount(accountName: String): Boolean;
var i: Integer;
begin
  Result := False;
  if frmMailbox.Profile = nil then
    Exit;
  if frmMailbox.Profile.Accounts.Count = 0 then
    Exit;

  for i := 0 to frmMailbox.Profile.Accounts.Count - 1 do begin
    if SameText(accountName, frmMailbox.Profile.Accounts[i].AccountName) then begin
      MessageDlg(Format(_('Account ''%s'' allready exists.'), [accountName]),
        mtError, [mbOK], 0);
      Result := True;
      break;
    end;
  end
end;

//if user exist then select it and return true
function TfrmNewAccountWizard.CheckProfile(profileName: String): Boolean;
var i: Integer;
begin
  Result := False;
  for i := 0 to frmMailbox.Profiles.Count - 1 do begin
    if SameText(profileName, frmMailbox.Profiles[i].UserName) then begin
      MessageDlg(Format(_('User ''%s'' already exist.'), [profileName]),
        mtError, [mbOK], 0);
      Result := True;
      break;
    end;
  end;
end;

procedure TfrmNewAccountWizard.wizardCancelButtonClick(Sender: TObject);
begin
  Self.Close;
end;

procedure TfrmNewAccountWizard.FormHide(Sender: TObject);
begin
  //try to write self position & size
  try
    frmMailbox.Profile.Config.WriteControlSettings(Self);
  except
  end;
end;

procedure TfrmNewAccountWizard.FormShow(Sender: TObject);
var i: Integer;
var t, l: Integer;
begin
  //translate me
  TranslateComponent(Self);

  Screen.Cursor := crHourGlass;
  prepareControls;
  wizard.ActivePageIndex := 0;

  //load pop & smtp settings
  if not popAndSmtpLoaded then begin
    if not FileExists(df.Application + 'popAndSmtp.xml') then begin
      MessageDlg(Format(_('Unable to find ''%s''.' + #13#10 +
        'This file is necessary for si.Mail to work properly.' + #13#10 + 'Please re-install si.Mail'),
        [df.Application + 'popAndSmtp.xml']), mtError, [mbOk], 0);
      Screen.Cursor := crDefault;
      Application.Terminate;
      Exit;
    end;
    popAndSmtpLoaded := True;
    serverSett := CreateXMLDoc;
    serverSett.Load(df.Application + 'popAndSmtp.xml');
  end;

  Screen.Cursor := crDefault;
  FCancled := True; //so we know if user cancled creation
  frmNewAccServerProperties.LoadDefaults;
  
  //try to read self position & size
  try
    frmMailbox.Profile.Config.ReadControlSettings(Self);
  except
    //automatic window positioning failed
    //so we just center the form on screen
    t := (Screen.Height div 2) - (Self.Height div 2);
    l := (Screen.Width div 2) - (Self.Width div 2);

    Self.Top := t;
    Self.Left := l;
  end;

end;

procedure TfrmNewAccountWizard.wizardSelectNextPage(Sender: TObject;
  FromPage: TJvWizardCustomPage; var ToPage: TJvWizardCustomPage);
var tmpBol: Boolean;
var i: Integer;
begin
  if FromPage = wizWelcome then begin
    //txtUser.SetFocus;
    if (frmMailbox.Profiles.Count > 0) then
      ToPage := wizAccount;
  end
  else if FromPage = wizProfile then begin
    if (Trim(txtProfile.Text) = '') and (frmMailbox.Profiles.Count = 0) then begin
      MessageDlg(_('Please write your name to Profile name field.'), mtError, [mbOK], 0);
      txtProfile.SetFocus;
      ToPage := nil;
    end
    else if txtPwd.Text <> txtRetypePwd.Text then begin
      MessageDlg(_('Passwords do not match.'), mtError, [mbOK], 0);
      txtPwd.SetFocus;
      ToPage := nil;
    end
    else begin
      txtProfile.Text := Trim(txtProfile.Text);
      //does user exist
      if checkProfile(txtProfile.Text) then begin
        txtProfile.SetFocus;
        exit;
      end;

      Screen.Cursor := crHourGlass;
      if frmMailbox.Profiles.Count > 0 then begin
        cmboxAccount.Clear;
        //find current user's accounts
        for i := 0 to frmMailbox.Profile.Accounts.Count - 1 do begin
          cmboxAccount.Items.Add(frmMailbox.Profile.Accounts[i].AccountName);
        end;
      end;
      txtYourName.Text := txtProfile.Text;

      Screen.Cursor := crDefault;
      if cmboxAccount.Items.Count = 0 then rbAcc2.Enabled := False
      else rbAcc2.Enabled := True;
    end;
  end
  else if FromPage = wizAccount then begin
    if rbAcc1.Checked then begin
      if Trim(txtAccountName1.Text) = '' then begin
        MessageDlg(_('Please write Account name to Account name field.'), mtError, [mbOK], 0);
        txtAccountName1.SetFocus;
        ToPage := nil;
      end
      else begin
        //does account exist
        if checkAccount(Trim(txtAccountName1.Text)) then begin
          txtAccountName1.SetFocus;
          ToPage := nil;
          exit;
        end;
      end;
    end
    else if rbAcc2.Checked then begin
      if Trim(txtAccountName2.Text) = '' then begin
        MessageDlg(_('Please write Account name to Account name field.'), mtError, [mbOK], 0);
        txtAccountName2.SetFocus;
      end
      else begin
        //does account exist
        if checkAccount(Trim(txtAccountName2.Text)) then begin
          txtAccountName2.SetFocus;
          ToPage := nil;
          exit;
        end;
      end;
    end;
  end
  else if FromPage = wizUser then begin
    if (Trim(txtYourName.Text) = '') or (Trim(txtEmail.Text) = '') or
      (Trim(txtLoginUser1.Text) = '') or (Trim(txtLoginPwd1.Text) = '') then begin
      MessageDlg(_('Please fill all fields.'), mtError, [mbOK], 0);
      txtYourName.SetFocus;
      ToPage := nil;
    end
    else begin
      if not ValidateEmail(txtEmail.Text) then begin
        txtEmail.SetFocus;
        ToPage := nil;
        Exit;
      end;
      if txtReplyEmail.Text <> '' then begin
        if ( not ValidateEmail(txtReplyEmail.Text)) then begin
          txtReplyEmail.SetFocus;
          ToPage := nil;
          Exit;
        end;
      end;
      Screen.Cursor := crHourGlass;
      findServerSettings;
      Screen.Cursor := crDefault;
      cmboxSmtpAuth.ItemIndex := 0;
    end;
  end
  else if FromPage = wizServer then begin
    if (Trim(txtIncoming.Text) = '') or (Trim(txtOutgoing.Text) = '') then begin
      MessageDlg(_('Please fill all fields.'), mtError, [mbOK], 0);
      txtIncoming.SetFocus;
      ToPage := nil;
    end
    else begin
      try
        accountSummary;
      except
      end;
    end;
  end;
end;

procedure TfrmNewAccountWizard.wizardSelectPriorPage(Sender: TObject;
  FromPage: TJvWizardCustomPage; var ToPage: TJvWizardCustomPage);
begin
  if (frmMailbox.Profiles.Count > 0) and (FromPage = wizAccount) then
    ToPage := wizWelcome;
end;

procedure TfrmNewAccountWizard.wizardFinishButtonClick(Sender: TObject);
begin
  CreateAccount;
  FCancled := False;
  Self.Close;
end;

procedure TfrmNewAccountWizard.txtSummaryNavigateComplete2(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  DeleteFile(URL);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -