org.apache.mailet.Mail.setAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中org.apache.mailet.Mail.setAttribute()方法的一些代码示例,展示了Mail.setAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mail.setAttribute()方法的具体详情如下:
包路径:org.apache.mailet.Mail
类名称:Mail
方法名:setAttribute

Mail.setAttribute介绍

[英]Associates an attribute with the given name and value with this Mail instance. If an attribute with the given name already exists, it is replaced, and the previous value is returned.

Conventionally, attribute names should follow the namespacing guidelines for Java packages. The Mailet API specification reserves names matching org.apache.james.* and org.apache.mailet.*.
[中]将具有给定名称和值的属性与此邮件实例关联。如果具有给定名称的属性已存在,则会替换该属性,并返回上一个值。
按照惯例,属性名应该遵循Java包的名称空间准则。Mailet API规范保留与组织匹配的名称。阿帕奇。詹姆斯。和组织。阿帕奇。mailet.

代码示例

代码示例来源:origin: org.apache.james/james-server-mailets

@Override
  public void service(Mail mail) throws MessagingException {
    mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, priority);
  }
}

代码示例来源:origin: org.apache.james/james-server-mailets

public ThrowingConsumer<MailAddress> addStorageDirective(Mail mail) {
    return recipient -> {
      String attributeNameForUser = MailStore.DELIVERY_PATH_PREFIX + usersRepository.getUser(recipient);
      mail.setAttribute(
        attributeNameForUser,
        targetFolderName);
    };

  }
}

代码示例来源:origin: org.apache.james/james-server-mailetcontainer-camel

@Override
public void sendMail(Mail mail, String state) throws MessagingException {
  mail.setAttribute(Mail.SENT_BY_MAILET, "true");
  mail.setState(state);
  rootMailQueue.enQueue(mail);
}

代码示例来源:origin: org.apache.james/james-server-jmap

public void send(Mail mail, MailMetadata metadata) throws MailQueueException {
    mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, metadata.getMessageId().serialize());
    mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, metadata.getUsername());
    queue.enQueue(mail);
  }
}

代码示例来源:origin: apache/james-project

@Test
void setAttributeShouldReturnPreviousValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  Serializable previous = mail.setAttribute(KEY, NEW_VALUE);
  assertThat(previous).isEqualTo(VALUE);
}

代码示例来源:origin: apache/james-project

@BeforeEach
void setUp() {
  mail = newMail();
  mail.setAttribute(ATTRIBUTE_1);
  mail.setAttribute(ATTRIBUTE_2);
}

代码示例来源:origin: apache/james-project

@Test
void setAttributeShouldReturnLatestValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  mail.setAttribute(KEY, NEW_VALUE);
  assertThat(mail.getAttribute(KEY)).isEqualTo(NEW_VALUE);
}

代码示例来源:origin: org.apache.james/james-server-mailets

private void reAttemptDelivery(Mail mail, int retries) throws MailQueue.MailQueueException {
  LOGGER.debug("Storing message {} into outgoing after {} retries", mail.getName(), retries);
  DeliveryRetriesHelper.incrementRetries(mail);
  mail.setLastUpdated(dateSupplier.get());
  // Something happened that will delay delivery. Store it back in the retry repository.
  long delay = getNextDelay(DeliveryRetriesHelper.retrieveRetries(mail));
  if (configuration.isUsePriority()) {
    // Use lowest priority for retries. See JAMES-1311
    mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.LOW_PRIORITY);
  }
  queue.enQueue(mail, delay, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: apache/james-project

@Test
  void setAttributeShouldReturnEmptyWhenNoPreviousValue() {
    assertThat(mail.setAttribute(ATTRIBUTE_1)).isEmpty();
  }
}

代码示例来源:origin: apache/james-project

@Test
void removeAttributeShouldReturnPreviousValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  Serializable previous = mail.removeAttribute(KEY);
  assertThat(previous).isEqualTo(VALUE);
}

代码示例来源:origin: apache/james-project

@BeforeEach
void setUp() {
  mail = newMail();
  mail.setAttribute(ATTRIBUTE_1);
}

代码示例来源:origin: apache/james-project

@Test
void setAttributeShouldReturnValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  assertThat(mail.getAttribute(KEY)).isEqualTo(VALUE);
}

代码示例来源:origin: apache/james-project

@Test
void setAttributeShouldReturnNullWhenNoPreviousValue() {
  Mail mail = newMail();
  Serializable previous = mail.setAttribute(KEY, VALUE);
  assertThat(previous).isNull();
}

代码示例来源:origin: apache/james-project

@Test
  void getAttributeNamesShouldReturnAttributeNames() {
    Mail mail = newMail();
    mail.setAttribute(KEY, VALUE);
    assertThat(mail.getAttributeNames()).containsOnly(KEY);
  }
}

代码示例来源:origin: org.apache.james/james-server-mailets

private Mail createAuthentificatedMail(MimeMessage message) throws Exception {
  Mail mail = createUnauthenticatedMail(message);
  mail.setAttribute(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME, message.getSender().toString());
  return mail;
}

代码示例来源:origin: apache/james-project

@Test
void getAttributeShouldNotReturnDeletedElements() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  mail.removeAttribute(KEY);
  assertThat(mail.getAttribute(KEY)).isNull();
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test(expected = MailboxRoleNotFoundException.class)
public void doneShouldThrowWhenSentDoesNotExist() throws Exception {
  MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
  mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
  MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
  ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession);
  mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
  mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
  testee.done(true);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void doneShouldNotThrowWhenMessageIsNotInOutbox() throws Exception {
  MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
  mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
  mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
  MessageManager messageManager = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession);
  ComposedMessageId sentMessageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession);
  mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, sentMessageId.getMessageId().serialize());
  mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
  
  testee.done(true);
}

代码示例来源:origin: org.apache.james/james-server-mailets

@Test
public final void testGetScriptNoScript() throws Exception {
  doThrow(new ScriptNotFoundException()).when(sieveRepository).getScript(USER, SCRIPT_NAME);
  MimeMessage message = prepareMimeMessage("GETSCRIPT \"" + SCRIPT_NAME.getValue() + "\"");
  Mail mail = createUnauthenticatedMail(message);
  mail.setAttribute(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME, USER.asString());
  mailet.service(mail);
  ensureResponse("Re: GETSCRIPT \"" + SCRIPT_NAME.getValue() + "\"", "NO (NONEXISTENT) \"There is no script by that name\"");
}

代码示例来源:origin: apache/james-project

@Test
  void shouldBeReplacable() {
    SoftAssertions.assertSoftly(
      softly -> {
        softly.assertThat(mail.setAttribute(ATTRIBUTE_1_BIS)).contains(ATTRIBUTE_1);
        softly.assertThat(mail.getAttribute(ATTRIBUTE_NAME_1)).contains(ATTRIBUTE_1_BIS);
      }
    );
  }
}

相关文章