public int SaveAutoreply(MailboxAutoreply autoreply) { var query = new SqlInsert(MailboxAutoreplyTable.TABLE_NAME, true) .InColumnValue(MailboxAutoreplyTable.Columns.MailboxId, autoreply.MailboxId) .InColumnValue(MailboxAutoreplyTable.Columns.Tenant, autoreply.Tenant) .InColumnValue(MailboxAutoreplyTable.Columns.TurnOn, autoreply.TurnOn) .InColumnValue(MailboxAutoreplyTable.Columns.OnlyContacts, autoreply.OnlyContacts) .InColumnValue(MailboxAutoreplyTable.Columns.TurnOnToDate, autoreply.TurnOnToDate) .InColumnValue(MailboxAutoreplyTable.Columns.FromDate, autoreply.FromDate) .InColumnValue(MailboxAutoreplyTable.Columns.ToDate, autoreply.ToDate) .InColumnValue(MailboxAutoreplyTable.Columns.Subject, autoreply.Subject) .InColumnValue(MailboxAutoreplyTable.Columns.Html, autoreply.Html); return(Db.ExecuteNonQuery(query)); }
protected MailboxAutoreply ToAutoreply(object[] r) { var obj = new MailboxAutoreply { MailboxId = Convert.ToInt32(r[0]), Tenant = Convert.ToInt32(r[1]), TurnOn = Convert.ToBoolean(r[2]), OnlyContacts = Convert.ToBoolean(r[3]), TurnOnToDate = Convert.ToBoolean(r[4]), FromDate = Convert.ToDateTime(r[5]), ToDate = Convert.ToDateTime(r[6]), Subject = Convert.ToString(r[7]), Html = Convert.ToString(r[8]) }; return(obj); }
public static MailBoxData ToMailBoxData(Mailbox mailbox, MailboxServer inServer, MailboxServer outServer, MailboxAutoreply autoreply) { var address = new MailAddress(mailbox.Address); var mailAutoReply = autoreply != null ? new MailAutoreplyData(autoreply.MailboxId, autoreply.Tenant, autoreply.TurnOn, autoreply.OnlyContacts, autoreply.TurnOnToDate, autoreply.FromDate, autoreply.ToDate, autoreply.Subject, autoreply.Html) : null; var inServerOldFormat = string.Format("{0}:{1}", inServer.Hostname, inServer.Port); var outServerOldFormat = string.Format("{0}:{1}", outServer.Hostname, outServer.Port); var mailboxData = new MailBoxData(mailbox.Tenant, mailbox.User, mailbox.Id, mailbox.Name, address, address.ToLogin(inServer.Username), mailbox.Password, inServerOldFormat, inServer.SocketType.ToEncryptionType(), inServer.Authentication.ToSaslMechanism(), mailbox.Imap, address.ToLogin(outServer.Username), mailbox.SmtpPassword, outServerOldFormat, outServer.SocketType.ToEncryptionType(), outServer.Authentication.ToSaslMechanism(), Convert.ToByte(mailbox.OAuthType), mailbox.OAuthToken) { Size = mailbox.SizeLast, MessagesCount = mailbox.MsgCountLast, ServerLoginDelay = mailbox.LoginDelay, BeginDate = mailbox.BeginDate, QuotaError = mailbox.QuotaError, AuthErrorDate = mailbox.DateAuthError, ImapIntervalsJson = mailbox.ImapIntervals, SmtpServerId = mailbox.SmtpServerId, InServerId = mailbox.ServerId, EMailInFolder = mailbox.EmailInFolder, MailAutoreply = mailAutoReply, AccessTokenRefreshed = false, //TODO: ??? Enabled = mailbox.Enabled, IsRemoved = mailbox.IsRemoved, IsTeamlab = mailbox.IsTeamlabMailbox }; return(mailboxData); }
public void EnableAutoreply(MailBoxData account, bool enabled) { account.MailAutoreply.TurnOn = enabled; var autoreply = new MailboxAutoreply { MailboxId = account.MailBoxId, Tenant = account.TenantId, FromDate = account.MailAutoreply.FromDate, ToDate = account.MailAutoreply.ToDate, Html = account.MailAutoreply.Html, OnlyContacts = account.MailAutoreply.OnlyContacts, TurnOnToDate = account.MailAutoreply.TurnOnToDate, Subject = account.MailAutoreply.Subject, TurnOn = account.MailAutoreply.TurnOn }; using (var daoFactory = new DaoFactory()) { var autoreplyDao = daoFactory.CreateMailboxAutoreplyDao(account.TenantId, account.UserId); var result = autoreplyDao.SaveAutoreply(autoreply); if (result <= 0) { throw new InvalidOperationException(); } var autoreplyHistoryDao = daoFactory.CreateMailboxAutoreplyHistoryDao(account.TenantId, account.UserId); result = autoreplyHistoryDao.DeleteAutoreplyHistory(account.MailBoxId); if (result <= 0) { throw new InvalidOperationException(); } } }
public MailAutoreplyData SaveAutoreply(int mailboxId, bool turnOn, bool onlyContacts, bool turnOnToDate, DateTime fromDate, DateTime toDate, string subject, string html) { if (fromDate == DateTime.MinValue) { throw new ArgumentException(@"Invalid parameter", "fromDate"); } if (turnOnToDate && toDate == DateTime.MinValue) { throw new ArgumentException(@"Invalid parameter", "toDate"); } if (turnOnToDate && toDate < fromDate) { throw new ArgumentException(@"Wrong date interval, toDate < fromDate", "fromDate"); } if (string.IsNullOrEmpty(html)) { throw new ArgumentException(@"Invalid parameter", "html"); } var imagesReplacer = new StorageManager(TenantId, UserId); html = imagesReplacer.ChangeEditorImagesLinks(html, mailboxId); var autoreply = new MailboxAutoreply { MailboxId = mailboxId, Tenant = TenantId, FromDate = fromDate, ToDate = toDate, Html = html, OnlyContacts = onlyContacts, TurnOnToDate = turnOnToDate, Subject = subject, TurnOn = turnOn }; using (var daoFactory = new DaoFactory()) { var daoMailbox = daoFactory.CreateMailboxDao(); if (!daoMailbox.CanAccessTo( new СoncreteUserMailboxExp(mailboxId, TenantId, UserId))) { throw new AccessViolationException("Mailbox is not owned by user."); } var result = daoFactory.CreateMailboxAutoreplyDao(TenantId, UserId).SaveAutoreply(autoreply); if (result <= 0) { throw new InvalidOperationException(); } } var resp = new MailAutoreplyData(autoreply.MailboxId, autoreply.Tenant, autoreply.TurnOn, autoreply.OnlyContacts, autoreply.TurnOnToDate, autoreply.FromDate, autoreply.ToDate, autoreply.Subject, autoreply.Html); return(resp); }