)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Mail (Ia.Ftn.Wa.Models.Provision.Access)

Public general use code classes and xml files that we've compiled and used over the years:

    1: using System.Net;
    2:  
    3: namespace Ia.Ftn.Wa.Models.Provision.Access
    4: {
    5:     ////////////////////////////////////////////////////////////////////////////
    6:  
    7:     /// <summary publish="true">
    8:     ///
    9:     /// </summary>
   10:     /// 
   11:     /// <remarks> 
   12:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   13:     ///
   14:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   15:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   16:     ///
   17:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   18:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   19:     /// 
   20:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   21:     /// 
   22:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   23:     /// </remarks> 
   24:     public static class Mail
   25:     {
   26:         private static Ia.Ftn.Cl.Models.Business.Mail mail;
   27:  
   28:         ////////////////////////////////////////////////////////////////////////////
   29:  
   30:         /// <summary>
   31:         ///
   32:         /// </summary>
   33:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Provision.Access.MailViewModel mailViewModel)
   34:         {
   35:             //Read();
   36:  
   37:             //Page_ViewModel();
   38:         }
   39:  
   40:         ////////////////////////////////////////////////////////////////////////////
   41:  
   42:         /// <summary>
   43:         ///
   44:         /// </summary>
   45:         public static void Post(ref Ia.Ftn.Wa.Models.Provision.Access.MailViewModel mailViewModel, string commandName)
   46:         {
   47:         }
   48:  
   49:         /*
   50:         ////////////////////////////////////////////////////////////////////////////
   51: 
   52:         /// <summary>
   53:         ///
   54:         /// </summary>
   55:         private static void CreateMailbox(object sender, EventArgs e)
   56:         {
   57:             bool b;
   58:             string result, mailboxName;
   59: 
   60:             mailboxName = WebUtility.HtmlDecode(createMailboxTextBox.Text);
   61: 
   62:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
   63:             {
   64:                 try
   65:                 {
   66:                     b = mail.AddFolder(mailboxName, out result);
   67: 
   68:                     createMailboxTextBox.Text = null;
   69: 
   70:                     if (b)
   71:                     {
   72:                         resultLabel.Text = "Success: " + result;
   73:                         resultLabel.CssClass = "success";
   74:                     }
   75:                     else
   76:                     {
   77:                         resultLabel.Text = "Error: " + result;
   78:                         resultLabel.CssClass = "error";
   79:                     }
   80:                 }
   81:                 catch (Exception ex)
   82:                 {
   83:                     resultLabel.Text = "Error: Could not create the mailbox. " + WebUtility.HtmlDecode(ex.Message);
   84:                     resultLabel.CssClass = "error";
   85:                 }
   86:             }
   87:             else
   88:             {
   89:                 resultLabel.Text = "You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة).";
   90:                 resultLabel.CssClass = "error";
   91:             }
   92:         }
   93: 
   94:         ////////////////////////////////////////////////////////////////////////////
   95: 
   96:         /// <summary>
   97:         ///
   98:         /// </summary>
   99:         private static void DeleteMailbox(object sender, EventArgs e)
  100:         {
  101:             bool b;
  102:             string result, mailboxName;
  103: 
  104:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
  105:             {
  106:                 if (mailboxDropDownList.SelectedIndex != -1)
  107:                 {
  108:                     try
  109:                     {
  110:                         mailboxName = mailboxDropDownList.SelectedValue;
  111: 
  112:                         b = mail.DeleteMailbox(mailboxName, out result);
  113: 
  114:                         if (b)
  115:                         {
  116:                             resultLabel.Text = "Success: " + result;
  117:                             resultLabel.CssClass = "success";
  118:                         }
  119:                         else
  120:                         {
  121:                             resultLabel.Text = "Error: " + result;
  122:                             resultLabel.CssClass = "error";
  123:                         }
  124:                     }
  125:                     catch (Exception ex)
  126:                     {
  127:                         resultLabel.Text = "Error: Could not delete the mailbox. " + WebUtility.HtmlDecode(ex.Message);
  128:                         resultLabel.CssClass = "error";
  129:                     }
  130:                 }
  131:             }
  132:             else
  133:             {
  134:                 resultLabel.Text = "You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة).";
  135:                 resultLabel.CssClass = "error";
  136:             }
  137:         }
  138: 
  139:         ////////////////////////////////////////////////////////////////////////////
  140:         ////////////////////////////////////////////////////////////////////////////
  141: 
  142:         /// <summary>
  143:         ///
  144:         /// </summary>
  145:         private static void CreateRegex(object sender, EventArgs e)
  146:         {
  147:             bool b;
  148:             string result, mailboxName, regex;
  149: 
  150:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
  151:             {
  152:                 mailboxName = mailboxDropDownList.SelectedValue;
  153: 
  154:                 regex = WebUtility.HtmlDecode(createRegexTextBox.Text);
  155: 
  156:                 try
  157:                 {
  158:                     b = mail.AddRegex(mailboxName, regex, out result);
  159: 
  160:                     createRegexTextBox.Text = null;
  161: 
  162:                     if (b)
  163:                     {
  164:                         resultLabel.Text = "Success: " + result;
  165:                         resultLabel.CssClass = "success";
  166:                     }
  167:                     else
  168:                     {
  169:                         resultLabel.Text = "Error: " + result;
  170:                         resultLabel.CssClass = "error";
  171:                     }
  172:                 }
  173:                 catch (Exception ex)
  174:                 {
  175:                     resultLabel.Text = "Error: Could not create the regex. " + WebUtility.HtmlDecode(ex.Message);
  176:                     resultLabel.CssClass = "error";
  177:                 }
  178:             }
  179:             else
  180:             {
  181:                 resultLabel.Text = "You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة).";
  182:                 resultLabel.CssClass = "error";
  183:             }
  184:         }
  185: 
  186:         ////////////////////////////////////////////////////////////////////////////
  187: 
  188:         /// <summary>
  189:         ///
  190:         /// </summary>
  191:         private static void DeleteRegex(object sender, EventArgs e)
  192:         {
  193:             bool b;
  194:             string result, regexName;
  195: 
  196:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
  197:             {
  198:                 if (regexDropDownList.SelectedIndex != -1)
  199:                 {
  200:                     try
  201:                     {
  202:                         regexName = regexDropDownList.SelectedValue;
  203: 
  204:                         b = mail.DeleteRegex(regexName, out result);
  205: 
  206:                         if (b)
  207:                         {
  208:                             resultLabel.Text = "Success: " + result;
  209:                             resultLabel.CssClass = "success";
  210:                         }
  211:                         else
  212:                         {
  213:                             resultLabel.Text = "Error: " + result;
  214:                             resultLabel.CssClass = "error";
  215:                         }
  216:                     }
  217:                     catch (Exception ex)
  218:                     {
  219:                         resultLabel.Text = "Error: Could not delete the regex. " + WebUtility.HtmlDecode(ex.Message);
  220:                         resultLabel.CssClass = "error";
  221:                     }
  222:                 }
  223:             }
  224:             else
  225:             {
  226:                 resultLabel.Text = "You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة).";
  227:                 resultLabel.CssClass = "error";
  228:             }
  229:         }
  230: 
  231:         ////////////////////////////////////////////////////////////////////////////
  232:         ////////////////////////////////////////////////////////////////////////////
  233: 
  234:         /// <summary>
  235:         ///
  236:         /// </summary>
  237:         private static void Save(object sender, EventArgs e)
  238:         {
  239:             bool b;
  240:             int mailboxCheckFrequencyInMinutes;
  241:             string s;//, result;
  242:             UriHostNameType uriHostNameType;
  243: 
  244:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
  245:             {
  246:                 mail.IsActive = isActiveCheckBox.Checked;
  247:                 mail.IsActiveDuringWorkingHoursOnly = isActiveDuringWorkingHoursOnlyCheckBox.Checked;
  248: 
  249:                 b = int.TryParse(mailboxCheckFrequencyInMinutesTextBox.Text, out mailboxCheckFrequencyInMinutes);
  250: 
  251:                 if (b)
  252:                 {
  253:                     if (mailboxCheckFrequencyInMinutes >= 5) // minimum five minutes
  254:                     {
  255:                         mail.MailboxCheckFrequencyInMinutes = mailboxCheckFrequencyInMinutes;
  256: 
  257:                         uriHostNameType = Uri.CheckHostName(hostTextBox.Text);
  258: 
  259:                         if (uriHostNameType != UriHostNameType.Unknown)
  260:                         {
  261:                             mail.Host = WebUtility.HtmlDecode(hostTextBox.Text);
  262: 
  263:                             if (Ia.Cl.Models.Default.IsEmail(userNameTextBox.Text))
  264:                             {
  265:                                 mail.UserName = WebUtility.HtmlDecode(userNameTextBox.Text);
  266: 
  267:                                 if (passwordTextBox.Text.Length != 0)
  268:                                 {
  269:                                     mail.Password = WebUtility.HtmlDecode(passwordTextBox.Text);
  270: 
  271:                                     mail.EnabledSsl = true;  // for gmail
  272: 
  273:                                     s = mail.SerializeToString();
  274: 
  275:                                     Ia.Ftn.Cl.Models.Data.Miscellaneous.CreateOrUpdate("MailboxAndEmailMovingManager", s);
  276:                                 }
  277:                                 else
  278:                                 {
  279:                                     resultLabel.Text = "Error: The password '" + passwordTextBox.Text + "' is not valid. ";
  280:                                     resultLabel.CssClass = "error";
  281:                                 }
  282:                             }
  283:                             else
  284:                             {
  285:                                 resultLabel.Text = "Error: The user name '" + userNameTextBox.Text + "' is not a valid email. ";
  286:                                 resultLabel.CssClass = "error";
  287:                             }
  288:                         }
  289:                         else
  290:                         {
  291:                             resultLabel.Text = "Error: The host name '" + hostTextBox.Text + "' is invalid. ";
  292:                             resultLabel.CssClass = "error";
  293:                         }
  294:                     }
  295:                     else
  296:                     {
  297:                         resultLabel.Text = "Error: Mailbox check frequency in minutes value should be at least five minutes. ";
  298:                         resultLabel.CssClass = "error";
  299:                     }
  300:                 }
  301:                 else
  302:                 {
  303:                     resultLabel.Text = "Error: Mailbox check frequency in minutes values is not a valid integer. ";
  304:                     resultLabel.CssClass = "error";
  305:                 }
  306:             }
  307:             else
  308:             {
  309:                 resultLabel.Text = "You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة).";
  310:                 resultLabel.CssClass = "error";
  311:             }
  312:         }
  313: 
  314:         ////////////////////////////////////////////////////////////////////////////
  315: 
  316:         /// <summary>
  317:         ///
  318:         /// </summary>
  319:         private static void Read()
  320:         {
  321:             string s;
  322: 
  323:             s = Ia.Ftn.Cl.Models.Data.Miscellaneous.Read("MailboxAndEmailMovingManager");
  324: 
  325:             if (s != null) mail = Ia.Ftn.Cl.Models.Business.Mail.DeserializeFromString(s);
  326:             else mail = new Ia.Ftn.Cl.Models.Business.Mail();
  327: 
  328:             //resultLabel.Text = "Success: Object read. ";
  329:             //resultLabel.CssClass = "success";
  330:         }
  331: 
  332:         ////////////////////////////////////////////////////////////////////////////
  333: 
  334:         /// <summary>
  335:         ///
  336:         /// </summary>
  337:         private static void Page_ViewModel()
  338:         {
  339:             mailboxDropDownList.SelectedIndex = -1;
  340:             mailboxDropDownList.DataSource = mail.MailboxList;
  341:             mailboxDropDownList.DataBind();
  342: 
  343:             regexDropDownList.SelectedIndex = -1;
  344:             regexDropDownList.DataSource = mail.MailRegexToMailboxList;
  345:             regexDropDownList.DataBind();
  346: 
  347:             isActiveCheckBox.Checked = mail.IsActive;
  348:             isActiveDuringWorkingHoursOnlyCheckBox.Checked = mail.IsActiveDuringWorkingHoursOnly;
  349:             mailboxCheckFrequencyInMinutesTextBox.Text = mail.MailboxCheckFrequencyInMinutes.ToString();
  350:             hostTextBox.Text = mail.Host;
  351:             userNameTextBox.Text = mail.UserName;
  352: 
  353:             passwordTextBox.Text = mail.Password;
  354:             passwordTextBox.Attributes.Add("value", mail.Password);
  355: 
  356:             if (mailboxDropDownList.Items.Count == 0)
  357:             {
  358:                 mailboxDropDownList.Enabled = false;
  359:                 deleteMailboxButton.Enabled = false;
  360:                 deleteRegexButton.Enabled = false;
  361:                 createRegexButton.Enabled = false;
  362:             }
  363:             else
  364:             {
  365:                 mailboxDropDownList.Enabled = true;
  366:                 deleteMailboxButton.Enabled = true;
  367: 
  368:                 if (regexDropDownList.Items.Count == 0) deleteRegexButton.Enabled = false;
  369:                 else deleteRegexButton.Enabled = true;
  370: 
  371:                 createRegexButton.Enabled = true;
  372:             }
  373: 
  374:             if (!Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, staff))
  375:             {
  376:                 isActiveCheckBox.Enabled = false;
  377:                 isActiveDuringWorkingHoursOnlyCheckBox.Enabled = false;
  378:                 mailboxCheckFrequencyInMinutesTextBox.Enabled = false;
  379:                 hostTextBox.Enabled = false;
  380:                 userNameTextBox.Enabled = false;
  381:                 passwordTextBox.Enabled = false;
  382:                 createMailboxTextBox.Enabled = false;
  383:                 mailboxDropDownList.Enabled = false;
  384:                 createRegexTextBox.Enabled = false;
  385:                 regexDropDownList.Enabled = false;
  386:                 saveButton.Enabled = false;
  387:             }
  388:         }
  389:         */
  390:  
  391:         ////////////////////////////////////////////////////////////////////////////
  392:         ////////////////////////////////////////////////////////////////////////////
  393:     }
  394:  
  395:     ////////////////////////////////////////////////////////////////////////////
  396:     ////////////////////////////////////////////////////////////////////////////
  397: }