Beispiel #1
0
  /**
   * Create a comment from the given email.
   *
   * @param message
   * @param target
   * @throws MessagingException
   * @throws MailHandlerException
   * @throws IOException
   * @throws NoSuchAlgorithmException
   */
  @Transactional
  public static Comment saveComment(IMAPMessage message, Resource target)
      throws MessagingException, MailHandlerException, IOException, NoSuchAlgorithmException {
    User author = IMAPMessageUtil.extractSender(message);

    if (!AccessControl.isProjectResourceCreatable(author, target.getProject(), target.getType())) {
      throw new PermissionDenied(
          cannotCreateMessage(author, target.getProject(), target.getType()));
    }

    Content parsedMessage = extractContent(message);

    Comment comment = makeNewComment(target, author, parsedMessage.body);

    comment.save();

    Map<String, Attachment> relatedAttachments =
        saveAttachments(parsedMessage.attachments, comment.asResource());

    if (new ContentType(parsedMessage.type).match(MimeType.HTML)) {
      // replace cid with attachments
      comment.contents = replaceCidWithAttachments(comment.contents, relatedAttachments);
      comment.update();
    }

    new OriginalEmail(message.getMessageID(), comment.asResource()).save();

    // Add the event
    addEvent(NotificationEvent.forNewComment(comment, author), message.getAllRecipients(), author);

    return comment;
  }
Beispiel #2
0
  /**
   * Create an issue from the given email.
   *
   * @param message
   * @param project
   * @throws MessagingException
   * @throws PermissionDenied
   * @throws IOException
   * @throws NoSuchAlgorithmException
   */
  static Issue saveIssue(IMAPMessage message, Project project)
      throws MessagingException, PermissionDenied, IOException, NoSuchAlgorithmException {
    User sender = IMAPMessageUtil.extractSender(message);
    if (!AccessControl.isProjectResourceCreatable(sender, project, ResourceType.ISSUE_POST)) {
      throw new PermissionDenied(cannotCreateMessage(sender, project, ResourceType.ISSUE_POST));
    }
    Content parsedMessage = extractContent(message);
    String messageId = message.getMessageID();
    Address[] recipients = message.getAllRecipients();
    String subject = message.getSubject();

    return saveIssue(subject, project, sender, parsedMessage, messageId, recipients);
  }
Beispiel #3
0
  /**
   * Create a review comment from the given email.
   *
   * @param message
   * @param target
   * @throws IOException
   * @throws MessagingException
   * @throws PermissionDenied
   * @throws NoSuchAlgorithmException
   */
  static void saveReviewComment(IMAPMessage message, Resource target)
      throws IOException, MessagingException, PermissionDenied, NoSuchAlgorithmException {
    User sender = IMAPMessageUtil.extractSender(message);

    if (!AccessControl.isProjectResourceCreatable(
        sender, target.getProject(), ResourceType.REVIEW_COMMENT)) {
      throw new PermissionDenied(
          cannotCreateMessage(sender, target.getProject(), target.getType()));
    }

    Content content = extractContent(message);
    String messageID = message.getMessageID();
    Address[] allRecipients = message.getAllRecipients();

    saveReviewComment(target, sender, content, messageID, allRecipients);
  }