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); }
public bool SaveToMongoDB() { if (!this.IsValid) { return(false); } logger.Info("Saving received eMail to Database."); string userDatabase = "email"; if (this._user.IsLoggedIn) { userDatabase = "email_user_" + this._user.Id; } else if (User.EMailExists(this.RecipientTo)) { string userId = User.GetIdByEMail(this.RecipientTo); if (userId != String.Empty) { userDatabase = "email_user_" + userId; } } MongoDatabase mongoDatabase = this._mongoServer.GetDatabase(userDatabase); MongoCollection mongoCollection = mongoDatabase.GetCollection <eMailEntity>("mails"); eMailEntity mailEntity = new eMailEntity { ClientName = this.ClientName, Time = this.Time, MailFrom = this.MailFrom, Subject = this.Subject, RecipientTo = this.RecipientTo, Message = this.Message, HeaderFrom = this.HeaderFrom, HeaderTo = this.HeaderTo, HeaderDate = this.HeaderDate, Folder = this.Folder, RawHeader = this.RawHeader }; if (this.HeaderCc.Count > 0) { mailEntity.HeaderCc = this.HeaderCc; } if (this.HeaderReplyTo != null && this.HeaderReplyTo.Address != String.Empty) { mailEntity.HeaderReplyTo = this.HeaderReplyTo; } try { WriteConcernResult result = mongoCollection.Save(mailEntity, WriteConcern.Acknowledged); return(result.Ok); } catch (Exception e) { Console.WriteLine("MongoCollection.Save Exception: " + e.Message); return(false); } }
public eMail(eMailEntity entity) { this._mongoServer = MyMongoDB.GetServer(); this.SetClientName(entity.ClientName); this.SetFrom(entity.MailFrom); this.SetHeaderFrom(entity.HeaderFrom); this.SetHeaderTo(entity.HeaderTo); this.SetId(entity.Id.ToString()); this.SetMessage(entity.Message); this.SetRecipient(entity.RecipientTo); this.SetReplyTo(entity.HeaderReplyTo); this.SetSubject(entity.Subject); this.SetTime(entity.Time); this.SetFolder(entity.Folder); this._flags = entity.Flags; }
public void AddEMail(eMail mail) { MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id); MongoCollection <eMailEntity> mongoCollection = mongoDatabase.GetCollection <eMailEntity>("mails"); eMailAddress headerFrom = new eMailAddress(this.Username, this.eMail); mail.SetReplyTo(this.Username, this.eMail); eMailEntity mailEntity = new eMailEntity { Time = mail.Time, MailFrom = mail.MailFrom, HeaderReplyTo = mail.HeaderReplyTo, Subject = mail.Subject, RecipientTo = mail.RecipientTo, ClientName = "eMailServer.NET", Message = mail.Message, HeaderFrom = headerFrom, RawHeader = mail.RawHeader }; WriteConcernResult result = mongoCollection.Insert(mailEntity, WriteConcern.Acknowledged); logger.Info("WriteConcernResult: " + result.Ok); }
public void AddEMail(eMail mail) { MongoDatabase mongoDatabase = this._mongoServer.GetDatabase("email_user_" + this._id); MongoCollection<eMailEntity> mongoCollection = mongoDatabase.GetCollection<eMailEntity>("mails"); eMailAddress headerFrom = new eMailAddress(this.Username, this.eMail); mail.SetReplyTo(this.Username, this.eMail); eMailEntity mailEntity = new eMailEntity { Time = mail.Time, MailFrom = mail.MailFrom, HeaderReplyTo = mail.HeaderReplyTo, Subject = mail.Subject, RecipientTo = mail.RecipientTo, ClientName = "eMailServer.NET", Message = mail.Message, HeaderFrom = headerFrom, RawHeader = mail.RawHeader }; WriteConcernResult result = mongoCollection.Insert(mailEntity, WriteConcern.Acknowledged); logger.Info("WriteConcernResult: " + result.Ok); }
public bool SaveToMongoDB() { if (!this.IsValid) { return false; } logger.Info("Saving received eMail to Database."); string userDatabase = "email"; if (this._user.IsLoggedIn) { userDatabase = "email_user_" + this._user.Id; } else if (User.EMailExists(this.RecipientTo)) { string userId = User.GetIdByEMail(this.RecipientTo); if (userId != String.Empty) { userDatabase = "email_user_" + userId; } } MongoDatabase mongoDatabase = this._mongoServer.GetDatabase(userDatabase); MongoCollection mongoCollection = mongoDatabase.GetCollection<eMailEntity>("mails"); eMailEntity mailEntity = new eMailEntity { ClientName = this.ClientName, Time = this.Time, MailFrom = this.MailFrom, Subject = this.Subject, RecipientTo = this.RecipientTo, Message = this.Message, HeaderFrom = this.HeaderFrom, HeaderTo = this.HeaderTo, HeaderDate = this.HeaderDate, Folder = this.Folder, RawHeader = this.RawHeader }; if (this.HeaderCc.Count > 0) { mailEntity.HeaderCc = this.HeaderCc; } if (this.HeaderReplyTo != null && this.HeaderReplyTo.Address != String.Empty) { mailEntity.HeaderReplyTo = this.HeaderReplyTo; } try { WriteConcernResult result = mongoCollection.Save(mailEntity, WriteConcern.Acknowledged); return result.Ok; } catch(Exception e) { Console.WriteLine("MongoCollection.Save Exception: " + e.Message); return false; } }