/// <summary> /// Handles the Click event of the cmdAddComment control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void CmdAddCommentClick(object sender, EventArgs e) { if (CommentHtmlEditor.Text.Trim().Length == 0) { return; } var comment = new IssueComment { IssueId = IssueId, Comment = CommentHtmlEditor.Text.Trim(), CreatorUserName = Security.GetUserName(), DateCreated = DateTime.Now }; var result = IssueCommentManager.SaveOrUpdate(comment); if (result) { //add history record var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); } CommentHtmlEditor.Text = String.Empty; BindComments(); }
/// <summary> /// Handles the ItemCommand event of the rptComments control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void RptCommentsItemCommand(object source, RepeaterCommandEventArgs e) { var pnlEditComment = e.Item.FindControl("pnlEditComment") as Panel; var pnlComment = e.Item.FindControl("pnlComment") as Panel; if (pnlEditComment == null) { return; } if (pnlComment == null) { return; } BugNET.UserControls.HtmlEditor editor; HiddenField commentNumber; IssueComment comment; switch (e.CommandName) { case "Save": editor = pnlEditComment.FindControl("EditCommentHtmlEditor") as BugNET.UserControls.HtmlEditor; if (editor != null) { if (editor.Text.Trim().Length == 0) { return; } commentNumber = (HiddenField)pnlEditComment.FindControl("commentNumber"); var commentId = Convert.ToInt32(commentNumber.Value); comment = IssueCommentManager.GetById(Convert.ToInt32(commentId)); comment.Comment = editor.Text.Trim(); IssueCommentManager.SaveOrUpdate(comment); editor.Text = String.Empty; commentNumber.Value = String.Empty; } pnlEditComment.Visible = false; pnlComment.Visible = true; pnlAddComment.Visible = true; BindComments(); break; case "Cancel": pnlEditComment.Visible = false; pnlComment.Visible = true; pnlAddComment.Visible = true; BindComments(); break; case "Delete": IssueCommentManager.Delete(Convert.ToInt32(e.CommandArgument)); BindComments(); break; case "Edit": comment = IssueCommentManager.GetById(Convert.ToInt32(e.CommandArgument)); // Show the edit comment panel for the comment pnlAddComment.Visible = false; pnlEditComment.Visible = true; pnlComment.Visible = false; // Insert the existing comment text in the edit control. editor = pnlEditComment.FindControl("EditCommentHtmlEditor") as BugNET.UserControls.HtmlEditor; if (editor != null) { editor.Text = comment.Comment; } // Save the comment ID for further editting. commentNumber = (HiddenField)e.Item.FindControl("commentNumber"); if (commentNumber != null) { commentNumber.Value = (string)e.CommandArgument; } break; } }
private bool ProcessNewComment(List <string> recipients, POP3_ClientMessage message, Mail_Message mailHeader, MailboxReaderResult result) { string messageFrom = string.Empty; if (mailHeader.From.Count > 0) { messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim(); } bool processed = false; foreach (var address in recipients) { Regex isReply = new Regex(@"(.*)(\+iid-)(\d+)@(.*)"); Match commentMatch = isReply.Match(address); if (commentMatch.Success && commentMatch.Groups.Count >= 4) { // we are in a reply and group 4 must contain the id of the original issue int issueId; if (int.TryParse(commentMatch.Groups[3].Value, out issueId)) { var _currentIssue = IssueManager.GetById(issueId); if (_currentIssue != null) { var project = ProjectManager.GetById(_currentIssue.ProjectId); var mailbody = Mail_Message.ParseFromByte(message.MessageToByte()); bool isHtml; List <MIME_Entity> attachments = null; string content = GetMessageContent(mailbody, project, out isHtml, ref attachments); IssueComment comment = new IssueComment { IssueId = issueId, Comment = content, DateCreated = mailHeader.Date }; // try to find if the creator is valid user in the project, otherwise take // the user defined in the mailbox config var users = UserManager.GetUsersByProjectId(project.Id); var emails = messageFrom.Split(';').Select(e => e.Trim().ToLower()); var user = users.Find(x => emails.Contains(x.Email.ToLower())); if (user != null) { comment.CreatorUserName = user.UserName; } else { // user not found continue; } var saved = IssueCommentManager.SaveOrUpdate(comment); if (saved) { //add history record var history = new IssueHistory { IssueId = issueId, CreatedUserName = comment.CreatorUserName, DateChanged = comment.DateCreated, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var projectFolderPath = Path.Combine(Config.UploadsFolderPath, project.UploadPath); // save attachments as new files int attachmentsSavedCount = 1; foreach (MIME_Entity mimeEntity in attachments) { string fileName; var contentType = mimeEntity.ContentType.Type.ToLower(); var attachment = new IssueAttachment { Id = 0, Description = "File attached by mailbox reader", DateCreated = DateTime.Now, ContentType = mimeEntity.ContentType.TypeWithSubtype, CreatorDisplayName = user.DisplayName, CreatorUserName = user.UserName, IssueId = issueId, ProjectFolderPath = projectFolderPath }; attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data; if (contentType.Equals("attachment")) // this is an attached email { fileName = mimeEntity.ContentDisposition.Param_FileName; } else if (contentType.Equals("message")) // message has no filename so we create one { fileName = string.Format("Attached_Message_{0}.eml", attachmentsSavedCount); } else { fileName = string.IsNullOrWhiteSpace(mimeEntity.ContentType.Param_Name) ? string.Format("untitled.{0}", mimeEntity.ContentType.SubType) : mimeEntity.ContentType.Param_Name; } attachment.FileName = fileName; var saveFile = IsAllowedFileExtension(fileName); var fileSaved = false; // can we save the file? if (saveFile) { fileSaved = IssueAttachmentManager.SaveOrUpdate(attachment); if (fileSaved) { attachmentsSavedCount++; } else { LogWarning("MailboxReader: Attachment could not be saved, please see previous logs"); } } } processed = true; // add the entry if the save did not throw any exceptions result.MailboxEntries.Add(new MailboxEntry()); } } } } } return(processed); }