示例#1
0
 private void butOK_Click(object sender, System.EventArgs e)
 {
     try {
         PIn.Int(textPort.Text);
     }
     catch {
         MsgBox.Show(this, "Invalid outgoing port number.");
         return;
     }
     try {
         PIn.Int(textPortIncoming.Text);
     }
     catch {
         MsgBox.Show(this, "Invalid incoming port number.");
         return;
     }
     if (string.IsNullOrWhiteSpace(textUsername.Text) ||
         !textUsername.Text.Contains("@"))                   //super basic validation
     {
         MsgBox.Show(this, "Please enter a valid email address.");
         return;
     }
     if (EmailAddresses.AddressExists(textUsername.Text, EmailAddressCur.EmailAddressNum))
     {
         MsgBox.Show(this, "This email address already exists.");
         return;
     }
     EmailAddressCur.SMTPserver         = PIn.String(textSMTPserver.Text);
     EmailAddressCur.EmailUsername      = PIn.String(textUsername.Text);
     EmailAddressCur.EmailPassword      = PIn.String(MiscUtils.Encrypt(textPassword.Text));
     EmailAddressCur.ServerPort         = PIn.Int(textPort.Text);
     EmailAddressCur.UseSSL             = checkSSL.Checked;
     EmailAddressCur.SenderAddress      = PIn.String(textSender.Text);
     EmailAddressCur.Pop3ServerIncoming = PIn.String(textSMTPserverIncoming.Text);
     EmailAddressCur.ServerPortIncoming = PIn.Int(textPortIncoming.Text);
     if (IsNew)
     {
         EmailAddresses.Insert(EmailAddressCur);
     }
     else
     {
         EmailAddresses.Update(EmailAddressCur);
     }
     DialogResult = DialogResult.OK;
 }
 private void butOK_Click(object sender, System.EventArgs e)
 {
     try {
         PIn.Int(textPort.Text);
     }
     catch {
         MsgBox.Show(this, "Invalid outgoing port number.");
         return;
     }
     try {
         PIn.Int(textPortIncoming.Text);
     }
     catch {
         MsgBox.Show(this, "Invalid incoming port number.");
         return;
     }
     if (string.IsNullOrWhiteSpace(textUsername.Text))
     {
         MsgBox.Show(this, "Please enter a valid email address.");
         return;
     }
     //Only checks against non-user email addresses.
     if (EmailAddresses.AddressExists(textUsername.Text, _emailAddressCur.EmailAddressNum))
     {
         MsgBox.Show(this, "This email address already exists.");
         return;
     }
     if (!textPassword.Text.IsNullOrEmpty() && !textAccessToken.Text.IsNullOrEmpty())
     {
         MsgBox.Show(this, "There is an email password and access token entered.  Please clear one and try again.");
         return;
     }
     _emailAddressCur.AccessToken  = textAccessToken.Text;
     _emailAddressCur.RefreshToken = textRefreshToken.Text;
     if (!_isNew && (!string.IsNullOrWhiteSpace(_emailAddressCur.AccessToken) || !string.IsNullOrWhiteSpace(_emailAddressCur.RefreshToken)) &&        //If has a token
         (_emailAddressCur.SMTPserver != PIn.String(textSMTPserver.Text) || _emailAddressCur.Pop3ServerIncoming != PIn.String(textSMTPserverIncoming.Text)))               //And changed a server
     {
         if (!MsgBox.Show(MsgBoxButtons.OKCancel, "There is an access token associated to this email address.  "
                          + "Changing servers will wipe out the access token and may require reauthentication.  Continue?"))
         {
             return;
         }
         _emailAddressCur.AccessToken  = "";
         _emailAddressCur.RefreshToken = "";
         //TODO: If this is a google token, we may want to tell Google we no longer require access to their account.
         //This will limit our total number of active users
     }
     _emailAddressCur.SMTPserver         = PIn.String(textSMTPserver.Text);
     _emailAddressCur.EmailUsername      = PIn.String(textUsername.Text);
     _emailAddressCur.EmailPassword      = PIn.String(MiscUtils.Encrypt(textPassword.Text));
     _emailAddressCur.ServerPort         = PIn.Int(textPort.Text);
     _emailAddressCur.UseSSL             = checkSSL.Checked;
     _emailAddressCur.SenderAddress      = PIn.String(textSender.Text);
     _emailAddressCur.Pop3ServerIncoming = PIn.String(textSMTPserverIncoming.Text);
     _emailAddressCur.ServerPortIncoming = PIn.Int(textPortIncoming.Text);
     _emailAddressCur.UserNum            = ((Userod)(textUserod.Tag))?.UserNum ?? 0;
     if (_isNew)
     {
         EmailAddresses.Insert(_emailAddressCur);
     }
     else
     {
         EmailAddresses.Update(_emailAddressCur);
     }
     DialogResult = DialogResult.OK;
 }