/** * Return the HookResult after run the hook * * this strongly typed version smoothly handle null sender and should be prefered. */ default HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { return doRcpt(session, sender.asOptional().orElse(null), rcpt); }
private boolean senderIsMailingList(Mail mail) { return mail.getMaybeSender() .asOptional() .map(MailAddress::getLocalPart) .map(localPart -> localPart.startsWith("owner-") || localPart.endsWith("-request") || localPart.equalsIgnoreCase("MAILER-DAEMON") || localPart.equalsIgnoreCase("LISTSERV") || localPart.equalsIgnoreCase("majordomo")) .orElse(false); }
public Optional<MailAddress> getReplyTo(Mail originalMail) { if (replyTo.isPresent()) { if (replyTo.get().equals(SpecialAddress.UNALTERED)) { return Optional.empty(); } return originalMail.getMaybeSender().asOptional(); } return Optional.empty(); } }
/** * Return the sender of the mail which was supplied int the MAIL FROM: * command. If its a "null" sender, null will get returned * * @deprecated @see {@link #getMaybeSender()} * * Note that SMTP null sender ( "<>" ) needs to be implicitly handled by the caller under the form of 'null' or * {@link MailAddress#nullSender()}. Replacement method adds type safety on this operation. * * @return sender */ @Deprecated default MailAddress getSender() { return getMaybeSender().asOptional().orElse(MailAddress.nullSender()); }
/** * Return the HookResult after run the hook * * This strongly typed version of do mail is safer to use. * * @since James 3.2.0 */ default HookResult doMail(SMTPSession session, MaybeSender sender) { return doMail(session, sender.asOptional().orElse(MailAddress.nullSender())); } }
private Optional<DLPConfigurationItem.Id> findFirstMatchingRule(Mail mail) { return mail.getMaybeSender() .asOptional() .flatMap(sender -> matchingRule(sender, mail)); }
private boolean isSenderLocal(Mail mail) { return mail.getMaybeSender().asOptional() .map(MailAddress::getDomain) .map(domain -> getMailetContext().isLocalServer(domain)) .orElse(false); }
private Set<MailAddress> getSender(Mail mail) { return OptionalUtils.toSet(mail.getMaybeSender().asOptional()); }
private Optional<String> retrieveSender(Mail mail) throws MessagingException { Optional<String> fromMime = StreamUtils.ofOptional( Optional.ofNullable(mail.getMessage()) .map(Throwing.function(MimeMessage::getFrom).orReturn(new Address[]{}))) .map(address -> (InternetAddress) address) .map(InternetAddress::getAddress) .findFirst(); Optional<String> fromEnvelope = mail.getMaybeSender().asOptional() .map(MailAddress::asString); return OptionalUtils.or( fromMime, fromEnvelope); } }
@Override public void service(Mail mail) throws MessagingException { String domain = mail.getMaybeSender() .asOptional() .map(MailAddress::getDomain) .map(Domain::asString) .orElse(""); MailRepositoryUrl repositoryUrl = MailRepositoryUrl.from(urlPrefix + domain); store(mail, repositoryUrl); if (!passThrough) { mail.setState(Mail.GHOST); } }
public VacationReply build(MimeMessageBodyGenerator mimeMessageBodyGenerator) throws MessagingException { Preconditions.checkState(mailRecipient != null, "Original recipient address should not be null"); Preconditions.checkState(originalMail.hasSender(), "Original sender address should not be null"); return new VacationReply(mailRecipient, OptionalUtils.toList(originalMail.getMaybeSender().asOptional()), generateMimeMessage(mimeMessageBodyGenerator)); }
@Override public void service(Mail mail) { LOGGER.info("Hello, World!"); LOGGER.info("You have mail from {}", mail.getMaybeSender().asOptional().map(MailAddress::getLocalPart)); } }
case FROM: case REVERSE_PATH: return mail.getMaybeSender().asOptional() .map(ImmutableSet::of) .orElse(ImmutableSet.of());
private void sendMessageWhenOutboxInTargetMailboxIds(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession, SetMessagesResponse.Builder builder) throws MailboxException, MessagingException, IOException { if (isTargetingOutbox(mailboxSession, listTargetMailboxIds(updateMessagePatch))) { Optional<MessageResult> maybeMessageToSend = messageIdManager.getMessages( ImmutableList.of(messageId), FetchGroupImpl.FULL_CONTENT, mailboxSession) .stream() .findFirst(); if (maybeMessageToSend.isPresent()) { MessageResult messageToSend = maybeMessageToSend.get(); MailImpl mail = buildMailFromMessage(messageToSend); assertUserIsSender(mailboxSession, mail.getMaybeSender().asOptional()); messageSender.sendMessage(messageId, mail, mailboxSession); referenceUpdater.updateReferences(messageToSend.getHeaders(), mailboxSession); } else { addMessageIdNotFoundToResponse(messageId, builder); } } }
public static MailDto fromMail(Mail mail, Set<AdditionalField> additionalFields) throws MessagingException, InaccessibleFieldException { Optional<MessageContent> messageContent = fetchMessage(additionalFields, mail); return new MailDto(mail.getName(), mail.getMaybeSender().asOptional().map(MailAddress::asString), mail.getRecipients().stream().map(MailAddress::asString).collect(Guavate.toImmutableList()), Optional.ofNullable(mail.getErrorMessage()), Optional.ofNullable(mail.getState()), Optional.ofNullable(mail.getRemoteHost()), Optional.ofNullable(mail.getRemoteAddr()), Optional.ofNullable(mail.getLastUpdated()), fetchAttributes(additionalFields, mail), fetchPerRecipientsHeaders(additionalFields, mail), fetchHeaders(additionalFields, mail), fetchTextBody(additionalFields, messageContent), fetchHtmlBody(additionalFields, messageContent), fetchMessageSize(additionalFields, mail)); }
@Test void asOptionalShouldReturnWrappedValue() { assertThat(MaybeSender.of(mailAddress).asOptional()) .contains(mailAddress); }
@Test void asOptionalShouldReturnEmptyWhenNullSender() { assertThat(MaybeSender.nullSender().asOptional()) .isEmpty(); }
@Test void asOptionalShouldReturnWrappedValue() { assertThat(MaybeSender.of(mailAddress).asOptional()) .contains(mailAddress); }
@Test void asOptionalShouldReturnEmptyWhenNullSender() { assertThat(MaybeSender.nullSender().asOptional()) .isEmpty(); }
public static MailQueueItemDTO from(ManageableMailQueue.MailQueueItemView mailQueueItemView) { return builder() .name(mailQueueItemView.getMail().getName()) .sender(mailQueueItemView.getMail().getMaybeSender().asOptional()) .recipients(mailQueueItemView.getMail().getRecipients()) .nextDelivery(mailQueueItemView.getNextDelivery()) .build(); }