本文整理了Java中org.apache.mailet.Mail.getMessageSize()
方法的一些代码示例,展示了Mail.getMessageSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mail.getMessageSize()
方法的具体详情如下:
包路径:org.apache.mailet.Mail
类名称:Mail
方法名:getMessageSize
[英]Returns the message size (including headers).
This is intended as a guide suitable for processing heuristics, and not a precise indication of the number of outgoing bytes that would be produced were the email to be encoded for transport. In cases where an exact value is not readily available or is difficult to determine (for example, when the fully transfer encoded message is not available) a suitable estimate may be returned.
[中]返回消息大小(包括标题)。
这是一个适用于处理启发式的指南,而不是一个精确的指示,如果要对传输的电子邮件进行编码,将产生多少传出字节。在准确值不容易获得或难以确定的情况下(例如,当完全传输编码的消息不可用时),可以返回适当的估计。
代码示例来源:origin: org.apache.james/james-server-protocols-smtp
@Override
public long getSize() {
try {
return mail.getMessageSize();
} catch (MessagingException e) {
return -1;
}
}
代码示例来源:origin: org.apache.james/james-server-smtpserver
/**
* @see org.apache.james.protocols.smtp.MailEnvelope#getSize()
*/
public int getSize() {
try {
return new Long(mail.getMessageSize()).intValue();
} catch (MessagingException e) {
return -1;
}
}
代码示例来源:origin: org.apache.james/james-server-mailets
@VisibleForTesting static Optional<Long> getMessageSizeEstimation(Mail mail) {
try {
return Optional.of(mail.getMessageSize())
.filter(size -> size > 0);
} catch (MessagingException e) {
LOGGER.debug("Could not estimate mail size", e);
return Optional.empty();
}
}
代码示例来源:origin: org.apache.james/apache-standard-mailets
public Collection<MailAddress> match(Mail mail) throws MessagingException {
if (mail.getMessageSize() > cutoff) {
return mail.getRecipients();
} else {
return null;
}
}
}
代码示例来源:origin: org.apache.james/james-server-webadmin-mailrepository
private static Optional<Long> fetchMessageSize(Set<AdditionalField> additionalFields, Mail mail) throws InaccessibleFieldException {
if (!additionalFields.contains(AdditionalField.MESSAGE_SIZE)) {
return Optional.empty();
}
try {
return Optional.of(mail.getMessageSize());
} catch (MessagingException e) {
throw new InaccessibleFieldException(AdditionalField.MESSAGE_SIZE, e);
}
}
代码示例来源:origin: org.apache.james/james-server-mailets
@Override
public int getSize() throws SieveMailException {
try {
return (int) getMail().getMessageSize();
} catch (MessagingException ex) {
throw new SieveMailException(ex);
}
}
代码示例来源:origin: org.apache.james/james-server-queue-jms
/**
* Produce the mail to the JMS Queue
*/
protected void produceMail(Map<String, Object> props, int msgPrio, Mail mail) throws JMSException, MessagingException, IOException {
ObjectMessage message = session.createObjectMessage();
for (Map.Entry<String, Object> entry : props.entrySet()) {
message.setObjectProperty(entry.getKey(), entry.getValue());
}
long size = mail.getMessageSize();
ByteArrayOutputStream out;
if (size > -1) {
out = new ByteArrayOutputStream((int) size);
} else {
out = new ByteArrayOutputStream();
}
mail.getMessage().writeTo(out);
// store the byte array in a ObjectMessage so we can use a
// SharedByteArrayInputStream later
// without the need of copy the day
message.setObject(out.toByteArray());
producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);
}
代码示例来源:origin: org.apache.james/james-server-mailets
@Test
public void getMessageInternalSizeShouldTransformNegativeIntoEmpty() throws MessagingException {
Mail mail = mock(Mail.class);
when(mail.getMessageSize()).thenReturn(-1L);
assertThat(NotifyMailetsMessage.getMessageSizeEstimation(mail))
.isEqualTo(Optional.empty());
}
代码示例来源:origin: org.apache.james/james-server-queue-jms
protected Map<String, Object> getJMSProperties(Mail mail, long nextDelivery) throws MessagingException {
Map<String, Object> props = new HashMap<>();
props.put(JAMES_NEXT_DELIVERY, nextDelivery);
props.put(JAMES_MAIL_ERROR_MESSAGE, mail.getErrorMessage());
props.put(JAMES_MAIL_LAST_UPDATED, mail.getLastUpdated().getTime());
props.put(JAMES_MAIL_MESSAGE_SIZE, mail.getMessageSize());
props.put(JAMES_MAIL_NAME, mail.getName());
// won't serialize the empty headers so it is mandatory
// to handle nulls when reconstructing mail from message
if (!mail.getPerRecipientSpecificHeaders().getHeadersByRecipient().isEmpty()) {
props.put(JAMES_MAIL_PER_RECIPIENT_HEADERS, SerializationUtil.serialize(mail.getPerRecipientSpecificHeaders()));
}
String recipientsAsString = joiner.join(mail.getRecipients());
props.put(JAMES_MAIL_RECIPIENTS, recipientsAsString);
props.put(JAMES_MAIL_REMOTEADDR, mail.getRemoteAddr());
props.put(JAMES_MAIL_REMOTEHOST, mail.getRemoteHost());
String sender = mail.getMaybeSender().asString("");
org.apache.james.util.streams.Iterators.toStream(mail.getAttributeNames())
.forEach(attrName -> props.put(attrName, SerializationUtil.serialize(mail.getAttribute(attrName))));
props.put(JAMES_MAIL_ATTRIBUTE_NAMES, joiner.join(mail.getAttributeNames()));
props.put(JAMES_MAIL_SENDER, sender);
props.put(JAMES_MAIL_STATE, mail.getState());
return props;
}
代码示例来源:origin: org.apache.james/james-server-mailets
@Test
public void getMessageInternalSizeShouldTransformZeroSizeIntoEmpty() throws MessagingException {
Mail mail = mock(Mail.class);
when(mail.getMessageSize()).thenReturn(0L);
assertThat(NotifyMailetsMessage.getMessageSizeEstimation(mail))
.isEqualTo(Optional.empty());
}
代码示例来源:origin: org.apache.james/james-server-mailets
@Test
public void getMessageInternalSizeShouldReturnSizeWhenAvailable() throws MessagingException {
long size = 42L;
Mail mail = mock(Mail.class);
when(mail.getMessageSize()).thenReturn(size);
assertThat(NotifyMailetsMessage.getMessageSizeEstimation(mail))
.isEqualTo(Optional.of(size));
}
代码示例来源:origin: org.apache.james/james-server-mailets
@Test
public void getMessageInternalSizeShouldTransformMessagingErrorIntoEmpty() throws MessagingException {
Mail mail = mock(Mail.class);
when(mail.getMessageSize()).thenThrow(new MessagingException());
assertThat(NotifyMailetsMessage.getMessageSizeEstimation(mail))
.isEqualTo(Optional.empty());
}
代码示例来源:origin: org.apache.james/james-server-queue-jms
map.put(names[4], m.getMessageSize());
map.put(names[5], m.getLastUpdated().getTime());
map.put(names[6], m.getRemoteAddr());
代码示例来源:origin: org.apache.james/james-server-mailets
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
try {
List<MailAddress> result = new ArrayList<>();
for (MailAddress mailAddress : mail.getRecipients()) {
String userName = usersRepository.getUser(mailAddress);
MailboxSession mailboxSession = mailboxManager.createSystemSession(userName);
MailboxPath mailboxPath = MailboxPath.inbox(mailboxSession);
QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
if (quotaManager.getMessageQuota(quotaRoot).isOverQuotaWithAdditionalValue(SINGLE_EMAIL) ||
quotaManager.getStorageQuota(quotaRoot).isOverQuotaWithAdditionalValue(mail.getMessageSize())) {
result.add(mailAddress);
}
}
return result;
} catch (MailboxException e) {
throw new MessagingException("Exception while checking quotas", e);
} catch (UsersRepositoryException e) {
throw new MessagingException("Exception while retrieving username", e);
}
}
}
代码示例来源:origin: org.apache.james/james-server-mailets
LOGGER.info("Attribute " + attributeName);
LOGGER.info("Message size: " + mail.getMessageSize());
LOGGER.info("Last updated: " + mail.getLastUpdated());
LOGGER.info("Remote Address: " + mail.getRemoteAddr());
代码示例来源:origin: org.apache.james/james-server-mailrepository-api
default void checkMailEquality(Mail actual, Mail expected) {
assertSoftly(Throwing.consumer(softly -> {
softly.assertThat(actual.getMessage().getContent()).isEqualTo(expected.getMessage().getContent());
softly.assertThat(actual.getMessageSize()).isEqualTo(expected.getMessageSize());
softly.assertThat(actual.getName()).isEqualTo(expected.getName());
softly.assertThat(actual.getState()).isEqualTo(expected.getState());
softly.assertThat(actual.getAttribute(TEST_ATTRIBUTE)).isEqualTo(expected.getAttribute(TEST_ATTRIBUTE));
softly.assertThat(actual.getErrorMessage()).isEqualTo(expected.getErrorMessage());
softly.assertThat(actual.getRemoteHost()).isEqualTo(expected.getRemoteHost());
softly.assertThat(actual.getRemoteAddr()).isEqualTo(expected.getRemoteAddr());
softly.assertThat(actual.getLastUpdated()).isEqualTo(expected.getLastUpdated());
softly.assertThat(actual.getPerRecipientSpecificHeaders()).isEqualTo(expected.getPerRecipientSpecificHeaders());
}));
}
内容来源于网络,如有侵权,请联系作者删除!