Пример #1
0
  @Override
  public Mail getMailById(String mailId) {
    final Mail prototype = new Mail();
    prototype.setId(mailId);

    return getMail(prototype);
  }
Пример #2
0
  @Override
  public Mail createMail(Mail mail) {
    mail.setId(Long.toString(new Date().getTime()));
    this.objectContainer.store(mail);
    this.objectContainer.commit();

    return mail;
  }
Пример #3
0
  /** Accept the representation of a mail received from a sender, and create it. */
  @Override
  public void acceptRepresentation(Representation entity) throws ResourceException {
    final Form form = new Form(entity);
    final Mail mail = new Mail();
    mail.setStatus(Mail.STATUS_RECEIVED);

    // Look for an existing contact or create it.
    final String senderAddress = form.getFirstValue("senderAddress");
    final String senderName = form.getFirstValue("senderName");

    Contact contact = getObjectsFacade().lookForContact(senderAddress, this.mailbox);
    if (contact == null) {
      contact = new Contact();
      contact.setMailAddress(senderAddress);
      contact.setName(senderName);
    }
    mail.setSender(contact);

    mail.setMessage(form.getFirstValue("message"));
    mail.setSubject(form.getFirstValue("subject"));
    // form2.add("sendingDate", mail.getSendingDate().toString());
    final Series<Parameter> recipients = form.subList("recipient");
    for (final Parameter recipient : recipients) {
      contact = getObjectsFacade().lookForContact(recipient.getValue(), this.mailbox);
      if (contact == null) {
        contact = new Contact();
        final String[] recipientValues = recipient.getValue().split("\\$");
        contact.setMailAddress(recipientValues[0]);
        contact.setName(recipientValues[1]);
      }
      mail.getRecipients().add(contact);
    }
    getObjectsFacade().createMail(this.mailbox, mail);
  }