Пример #1
0
        public eMail GetEMail(string id)
        {
            MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id);
            MongoCollection <eMailEntity> mongoCollection = mongoDatabase.GetCollection <eMailEntity>("mails");

            IMongoQuery query = Query <eMailEntity> .Where(e => e.Id == new ObjectId(id));

            eMailEntity entity = mongoCollection.FindOne(query);

            if (entity != null)
            {
                eMail mail = new eMail();
                mail.SetId(entity.Id.ToString());
                mail.SetClientName(entity.ClientName);
                mail.SetFrom(entity.MailFrom);
                mail.SetMessage(entity.Message);
                mail.SetRecipient(entity.RecipientTo);
                mail.SetSubject(entity.Subject);
                mail.SetHeaderFrom(entity.HeaderFrom);
                mail.SetHeaderTo(entity.HeaderTo);
                mail.SetTime(entity.Time);
                return(mail);
            }

            return(null);
        }
Пример #2
0
        public List <eMail> GetEmails(int offset, int limit)
        {
            List <eMail> eMails = new List <eMail>();

            MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id);
            MongoCollection <eMailEntity> mongoCollection = mongoDatabase.GetCollection <eMailEntity>("mails");

            //IMongoQuery query = Query<eMailEntity>.Where(e => e.RecipientTo == this.eMail);
            //MongoCursor<eMailEntity> mongoCursor = mongoCollection.Find(query).SetSkip(offset).SetLimit(limit);
            MongoCursor <eMailEntity> mongoCursor = mongoCollection.FindAll().SetSkip(offset).SetLimit(limit);

            foreach (eMailEntity entity in mongoCursor)
            {
                eMail mail = new eMail();
                mail.SetId(entity.Id.ToString());
                mail.SetClientName(entity.ClientName);
                mail.SetFrom(entity.MailFrom);
                mail.SetMessage(entity.Message);
                mail.SetRecipient(entity.RecipientTo);
                mail.SetSubject(entity.Subject);
                mail.SetHeaderFrom(entity.HeaderFrom);
                mail.SetHeaderTo(entity.HeaderTo);
                mail.SetTime(entity.Time);
                eMails.Add(mail);
            }

            return(eMails);
        }
Пример #3
0
        private void Mail(string rawUrl, NameValueCollection queryString)
        {
            if (!this.User.IsLoggedIn)
            {
                throw new UnauthorizedAccessException("access denied");
            }

            XmlNode    XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
            XmlElement XmlMail = this._doc.CreateElement("mail");

            rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
            switch (rawUrl)
            {
            case "get":
                if (queryString["id"] != null && queryString["id"] != String.Empty)
                {
                    eMail mail = this.User.GetEMail(queryString["id"]);
                    if (mail != null)
                    {
                        XmlMail.SetAttribute("from", mail.MailFrom);
                        XmlMail.SetAttribute("to", mail.RecipientTo);
                        XmlMail.SetAttribute("subject", mail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = mail.Message;
                        XmlMail.AppendChild(XmlMessage);
                    }
                }
                break;

            case "write":
                if (this.Request.HttpMethod == "POST")
                {
                    using (HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
                        string toEMail = String.Empty;
                        string subject = String.Empty;
                        string message = String.Empty;

                        if (postRequest.Parameters["email"] != null)
                        {
                            toEMail = postRequest.Parameters["email"];
                        }
                        if (postRequest.Parameters["subject"] != null)
                        {
                            subject = postRequest.Parameters["subject"];
                        }
                        if (postRequest.Parameters["message"] != null)
                        {
                            message = postRequest.Parameters["message"];
                        }

                        eMail newEMail = new eMail();
                        newEMail.SetFrom(this.User.eMail);
                        newEMail.SetRecipient(toEMail);
                        newEMail.SetSubject(subject);
                        newEMail.SetMessage(message);

                        XmlMail.SetAttribute("from", newEMail.MailFrom);
                        XmlMail.SetAttribute("to", newEMail.RecipientTo);
                        XmlMail.SetAttribute("subject", newEMail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");

                        /*
                         * foreach(string recipient in newEMail.Recipients) {
                         *      XmlElement XmlRecipient = this._doc.CreateElement("recipient");
                         *      XmlRecipient.SetAttribute("email", recipient);
                         *      XmlRecipients.AppendChild(XmlRecipient);
                         * }
                         */
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = newEMail.Message;
                        XmlMail.AppendChild(XmlMessage);

                        this.User.AddEMail(newEMail);
                        newEMail.Send();
                    }
                }
                break;
            }

            XmlRoot.AppendChild(XmlMail);
        }
Пример #4
0
		public eMail GetEMail(string id) {
			MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id);
			MongoCollection<eMailEntity> mongoCollection = mongoDatabase.GetCollection<eMailEntity>("mails");

			IMongoQuery query = Query<eMailEntity>.Where(e => e.Id == new ObjectId(id));
			eMailEntity entity = mongoCollection.FindOne(query);
			if (entity != null) {
				eMail mail = new eMail();
				mail.SetId(entity.Id.ToString());
				mail.SetClientName(entity.ClientName);
				mail.SetFrom(entity.MailFrom);
				mail.SetMessage(entity.Message);
				mail.SetRecipient(entity.RecipientTo);
				mail.SetSubject(entity.Subject);
				mail.SetHeaderFrom(entity.HeaderFrom);
				mail.SetHeaderTo(entity.HeaderTo);
				mail.SetTime(entity.Time);
				return mail;
			}

			return null;
		}
Пример #5
0
		public List<eMail> GetEmails(int offset, int limit) {
			List<eMail> eMails = new List<eMail>();

			MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id);
			MongoCollection<eMailEntity> mongoCollection = mongoDatabase.GetCollection<eMailEntity>("mails");

			//IMongoQuery query = Query<eMailEntity>.Where(e => e.RecipientTo == this.eMail);
			//MongoCursor<eMailEntity> mongoCursor = mongoCollection.Find(query).SetSkip(offset).SetLimit(limit);
			MongoCursor<eMailEntity> mongoCursor = mongoCollection.FindAll().SetSkip(offset).SetLimit(limit);
			foreach(eMailEntity entity in mongoCursor) {
				eMail mail = new eMail();
				mail.SetId(entity.Id.ToString());
				mail.SetClientName(entity.ClientName);
				mail.SetFrom(entity.MailFrom);
				mail.SetMessage(entity.Message);
				mail.SetRecipient(entity.RecipientTo);
				mail.SetSubject(entity.Subject);
				mail.SetHeaderFrom(entity.HeaderFrom);
				mail.SetHeaderTo(entity.HeaderTo);
				mail.SetTime(entity.Time);
				eMails.Add(mail);
			}

			return eMails;
		}
		private void Mail(string rawUrl, NameValueCollection queryString) {
			if (!this.User.IsLoggedIn) {
				throw new UnauthorizedAccessException("access denied");
			}

			XmlNode XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
			XmlElement XmlMail = this._doc.CreateElement("mail");

			rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
			switch(rawUrl) {
				case "get":
					if (queryString["id"] != null && queryString["id"] != String.Empty) {
						eMail mail = this.User.GetEMail(queryString["id"]);
						if (mail != null) {
							XmlMail.SetAttribute("from", mail.MailFrom);
							XmlMail.SetAttribute("to", mail.RecipientTo);
							XmlMail.SetAttribute("subject", mail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = mail.Message;
							XmlMail.AppendChild(XmlMessage);
						}
					}
					break;

				case "write":
					if (this.Request.HttpMethod == "POST") {
						using(HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
							string toEMail = String.Empty;
							string subject = String.Empty;
							string message = String.Empty;

							if (postRequest.Parameters["email"] != null) {
								toEMail = postRequest.Parameters["email"];
							}
							if (postRequest.Parameters["subject"] != null) {
								subject = postRequest.Parameters["subject"];
							}
							if (postRequest.Parameters["message"] != null) {
								message = postRequest.Parameters["message"];
							}

							eMail newEMail = new eMail();
							newEMail.SetFrom(this.User.eMail);
							newEMail.SetRecipient(toEMail);
							newEMail.SetSubject(subject);
							newEMail.SetMessage(message);

							XmlMail.SetAttribute("from", newEMail.MailFrom);
							XmlMail.SetAttribute("to", newEMail.RecipientTo);
							XmlMail.SetAttribute("subject", newEMail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							/*
							foreach(string recipient in newEMail.Recipients) {
								XmlElement XmlRecipient = this._doc.CreateElement("recipient");
								XmlRecipient.SetAttribute("email", recipient);
								XmlRecipients.AppendChild(XmlRecipient);
							}
							*/
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = newEMail.Message;
							XmlMail.AppendChild(XmlMessage);

							this.User.AddEMail(newEMail);
							newEMail.Send();
						}
					}
					break;
			}

			XmlRoot.AppendChild(XmlMail);
		}