/// <summary>
        /// 查询未激活且未过期的邮件
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        public mail_vertification GetDataByMailAdress(string mail, MailType mailType = MailType.Activation)
        {
            var sql = @"SELECT * FROM mail_vertification
WHERE mail_address = @address
AND is_active = 0
AND expire_time > CURRENT_TIMESTAMP
AND mail_type = @type";

            return(Broker.Retrieve <mail_vertification>(sql, new Dictionary <string, object>()
            {
                { "@address", mail }, { "@type", mailType.ToString() }
            }));
        }
Beispiel #2
0
        //constructor resposnsible for showing email
        public SendMessageWindow(Mail mail, MainWindow mainWindow, Manager mManager, MailType mailType)
        {
            if (isSendMessageManagerInitialized == false)
            {
                messageManager = new SendMessageManager(this);
                isSendMessageManagerInitialized = true;
            }
            mWindow = mainWindow;
            manager = mManager;
            InitializeComponent();

            if (mailType.ToString() == "view")
            {
                messageManager.ViewMessage(mail, manager);
            }
            else if (mailType.ToString() == "reply")
            {
                messageManager.ReplyMessage(mail, manager, mWindow);
            }
            else if (mailType.ToString() == "replyToAll")
            {
                //if there were no other receivers than do just normal reply
                if (!mail.Sender.Contains(","))
                {
                    messageManager.ReplyMessage(mail, manager, mWindow);
                }
                else
                {
                    messageManager.ReplyToAllMessage(mail, manager, mWindow);
                }
            }
            else if (mailType.ToString() == "forward")
            {
                messageManager.ForwardMessage(mail, mWindow, manager);
            }
        }
Beispiel #3
0
        public static CodeModel CodeModelCreator(string rawCode, UserModel userModel, DateTime creationDate, DateTime expireDate, MailType typeOfCode)
        {
            CodeModel userCode = new CodeModel();

            userCode.Idc          = Guid.NewGuid().ToString();
            userCode.Code         = rawCode;
            userCode.UserId       = userModel.Id;
            userCode.UserLogin    = userModel.UserLogin;
            userCode.CreationTime = creationDate;
            userCode.ExpireTime   = expireDate;
            userCode.TypeOfCode   = typeOfCode.ToString();
            userCode.IsActive     = true;

            return(userCode);
        }
Beispiel #4
0
        public static bool IsCodeValid(CodeModel codeModel, MailType type)
        {
            DateTime now = DateTime.UtcNow;

            if (codeModel.WasUsed || !codeModel.IsActive)
            {
                return(false);
            }
            if (codeModel.ExpireTime <= now)
            {
                return(false);
            }
            if (codeModel.TypeOfCode != type.ToString())
            {
                return(false);
            }
            return(true);
        }
        private static List <string> GetAttachments(Context db2, MailType mailType)
        {
            var result = new List <string>();

            // U:\WebApps\ProducerInterface\bin\ -> U:\WebApps\ProducerInterface\var\
            var pathToBaseDir = ConfigurationManager.AppSettings["PathToBaseDir"];
            var baseDir       = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathToBaseDir));

            if (!Directory.Exists(baseDir))
            {
                throw new NotSupportedException($"Не найдена директория {baseDir} для сохранения файлов");
            }

            // общая директория медиафайлов
            var dir = Path.Combine(baseDir, "MediaFiles");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            // поддиректория для хранения файлов данного типа писем
            var subdir = Path.Combine(baseDir, "MediaFiles", mailType.ToString());

            if (!Directory.Exists(subdir))
            {
                Directory.CreateDirectory(subdir);
            }

            // записали файлы в директорию
            var email = db2.Emails.Find((int)mailType);

            foreach (var mediaFile in email.MediaFiles)
            {
                var file = new FileInfo($"{subdir}\\{mediaFile.ImageName}");
                if (!file.Exists)
                {
                    File.WriteAllBytes(file.FullName, mediaFile.ImageFile);
                }
                result.Add(file.FullName);
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieves the template for the mail.
        /// </summary>
        /// <param name="mailType"> Which mail type we are sending. </param>
        /// <param name="isHtml"> Whether the returned body is HTML. </param>
        /// <returns> The template. </returns>
        private string GetTemplate(MailType mailType, out bool isHtml)
        {
            if (mailType != MailType.Invite && mailType != MailType.Iteration && mailType != MailType.Request &&
                mailType != MailType.Response && mailType != MailType.Reminder)
                throw new ArgumentException("mailType");

            if (!mailBodies.ContainsKey(mailType))
            {
                string res = null;
                string path = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
                bool templateIsHtml = false;
                try
                {
                    string fileName = Path.Combine(path, mailType.ToString() + ".html");
                    if (!File.Exists(fileName))
                        fileName = Path.Combine(path, mailType.ToString() + ".txt");
                    else
                        templateIsHtml = true;

                    if (File.Exists(fileName))
                    {
                        res = File.ReadAllText(fileName);
                        logger.Log("Using template @ {0}", fileName);
                    }
                }
                catch (IOException e)
                {
                    // Eat the exception.
                    logger.Log(e.ToString());
                }

                if (res == null)
                {
                    templateIsHtml = false; // We could have discovered an html file but then failed to read it.
                    switch (mailType)
                    {
                        case MailType.Request:
                            res = Request;
                            break;
                        case MailType.Invite:
                            res = Invitation;
                            break;
                        case MailType.Iteration:
                            res = Iteration;
                            break;
                        case MailType.Response:
                            res = Response;
                            break;
                        case MailType.Reminder:
                            res = Reminder;
                            break;
                    }
                }

                mailBodies[mailType] = PrepTemplate(res);
                mailBodiesIsHtml[mailType] = templateIsHtml;
            }

            isHtml = mailBodiesIsHtml[mailType];
            return mailBodies[mailType];
        }
Beispiel #7
0
        /// <summary>
        /// Get the mail subject and body.
        /// </summary>
        /// <param name="mailType">Type of mail</param>
        /// <param name="logger">Log errors to</param>
        /// <returns>Subject and body</returns>
        public Tuple<string, string> GetMailText(MailType mailType, ILogger logger)
        {
            string file = Path.Combine(Path.Combine(Application.StartupPath, "messages"), mailType.ToString());

              if (File.Exists(file))
              {
            string text = File.ReadAllText(file, Encoding.UTF8);

            if (text.Contains(Environment.NewLine))
            {
              string subject = text.Substring(0, text.IndexOf(Environment.NewLine));
              string body = text.Substring(text.IndexOf(Environment.NewLine) + Environment.NewLine.Length);
              return new Tuple<string, string>(subject, body);
            }
            else
            {
              return new Tuple<string, string>("Unknown PiVote Message", text);
            }
              }
              else
              {
            logger.Log(LogLevel.Warning, "Mail message file {0} not present.", file);
            return new Tuple<string, string>("Unknown PiVote Message", "This this an unknown message from PiVote. Please contact your administrator.");
              }
        }