public static boolean isSpecialAddress(MailAddress mailAddress) { return mailAddress.getDomain().equals(AddressMarker.ADDRESS_MARKER); } }
private Domain retrieveTargetHostname(Mail mail) { Preconditions.checkArgument(!mail.getRecipients().isEmpty(), "Mail should have recipients to attempt delivery"); MailAddress rcpt = Iterables.getFirst(mail.getRecipients(), null); return rcpt.getDomain(); }
public static User fromMailAddress(MailAddress address) { Preconditions.checkNotNull(address); return new User(address.getLocalPart(), Optional.of(address.getDomain())); }
public static User fromMailAddress(MailAddress address) { Preconditions.checkNotNull(address); return new User(address.getLocalPart(), Optional.of(address.getDomain())); }
private Map<Domain, Collection<MailAddress>> groupByServer(Collection<MailAddress> recipients) { // Must first organize the recipients into distinct servers (name made case insensitive) HashMultimap<Domain, MailAddress> groupByServerMultimap = HashMultimap.create(); for (MailAddress recipient : recipients) { groupByServerMultimap.put(recipient.getDomain(), recipient); } return groupByServerMultimap.asMap(); }
@VisibleForTesting List<MailAddress> handleMappings(Mappings mappings, Mail mail, MailAddress recipient) { boolean isLocal = true; Map<Boolean, List<MailAddress>> mailAddressSplit = mappings.asStream() .map(mapping -> mapping.appendDomainIfNone(defaultDomainSupplier)) .map(Mapping::asMailAddress) .flatMap(OptionalUtils::toStream) .collect(Collectors.partitioningBy(mailAddress -> mailetContext.isLocalServer(mailAddress.getDomain()))); forwardToRemoteAddress(mail, recipient, mailAddressSplit.get(!isLocal)); return mailAddressSplit.get(isLocal); }
private boolean isRedirected(MailAddress recipient, String username) { LOGGER.debug("Unknown user {} check if it's an alias", username); try { Mappings targetString = recipientRewriteTable.getMappings(recipient.getLocalPart(), recipient.getDomain()); if (!targetString.isEmpty()) { return true; } } catch (ErrorMappingException e) { return true; } catch (RecipientRewriteTableException e) { LOGGER.info("Unable to access RecipientRewriteTable", e); return false; } return false; }
private boolean belongsToLocalDomain(MaybeSender maybeSender) { Preconditions.checkArgument(!maybeSender.isNullSender()); return isLocalDomain(maybeSender.get().getDomain()); }
private Optional<DLPConfigurationItem.Id> matchingRule(MailAddress address, Mail mail) { return rulesLoader.load(address.getDomain()).match(mail); }
@Override public boolean isLocalEmail(MailAddress mailAddress) { if (mailAddress != null) { if (!isLocalServer(mailAddress.getDomain())) { return false; } try { return localusers.contains(localusers.getUser(mailAddress)); } catch (UsersRepositoryException e) { LOGGER.error("Unable to access UsersRepository", e); } } return false; }
private RrtExecutionResult executeRrtForRecipient(Mail mail, MailAddress recipient) { try { Mappings mappings = virtualTableStore.getMappings(recipient.getLocalPart(), recipient.getDomain()); if (mappings != null && !mappings.isEmpty()) { List<MailAddress> newMailAddresses = handleMappings(mappings, mail, recipient); return RrtExecutionResult.success(newMailAddresses); } return RrtExecutionResult.success(recipient); } catch (ErrorMappingException | RecipientRewriteTableException e) { LOGGER.warn("Could not rewrite recipient {}", recipient, e); return RrtExecutionResult.error(recipient); } }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (!isLocalDomain(session, rcpt.getDomain())) { return HookResult.DECLINED; } if (!isValidRecipient(session, rcpt)) { return reject(rcpt); } return HookResult.DECLINED; }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (!session.isRelayingAllowed()) { Domain toDomain = rcpt.getDomain(); if (!isLocalDomain(toDomain)) { if (session.isAuthSupported()) { return AUTH_REQUIRED; } else { return RELAYING_DENIED; } } } return HookResult.DECLINED; }
@Override public Collection<MailAddress> match(Mail mail) { try { if (mail.hasSender()) { recipientRewriteTable.getMappings(mail.getMaybeSender().get().getLocalPart(), mail.getMaybeSender().get().getDomain()); } } catch (RecipientRewriteTable.TooManyMappingException e) { return mail.getRecipients(); } catch (Exception e) { LoggerFactory.getLogger(IsSenderInRRTLoop.class).warn("Error while executing RRT"); } return ImmutableList.of(); } }
/** * Test method for {@link MailAddress#getDomain()}. */ @Test public void testGetDomain() { try { MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); assertThat(a.getDomain()).isEqualTo(GOOD_DOMAIN); } catch (AddressException e) { System.out.println("AddressException" + e.getMessage()); assertThat(false).describedAs(e.getMessage()).isTrue(); } }
/** * Test method for {@link MailAddress#getDomain()}. */ @Test public void testGetDomain() { try { MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); assertThat(a.getDomain()).isEqualTo(GOOD_DOMAIN); } catch (AddressException e) { System.out.println("AddressException" + e.getMessage()); assertThat(false).describedAs(e.getMessage()).isTrue(); } }
@Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }
@Test public void matchShouldReturnEmptyWhenLoopButNoRecipient() throws Exception { recipientRewriteTable.addAddressMapping(MappingSource.fromUser(SENDER.getLocalPart(), SENDER.getDomain()), RECIPIENT1.asString()); recipientRewriteTable.addAddressMapping(MappingSource.fromUser(RECIPIENT1.getLocalPart(), RECIPIENT1.getDomain()), SENDER.asString()); Collection<MailAddress> result = testee.match(FakeMail.builder() .sender(SENDER) .build()); assertThat(result).isEmpty(); }
@Test public void matchShouldReturnRecipientsWhenLoop() throws Exception { recipientRewriteTable.addAddressMapping(MappingSource.fromUser(SENDER.getLocalPart(), SENDER.getDomain()), RECIPIENT1.asString()); recipientRewriteTable.addAddressMapping(MappingSource.fromUser(RECIPIENT1.getLocalPart(), RECIPIENT1.getDomain()), SENDER.asString()); Collection<MailAddress> result = testee.match(FakeMail.builder() .sender(SENDER) .recipient(RECIPIENT2) .build()); assertThat(result).containsOnly(RECIPIENT2); }
@Test public void matchShouldReturnEmptyWhenNoRRTLoop() throws Exception { recipientRewriteTable.addAddressMapping(MappingSource.fromUser(SENDER.getLocalPart(), SENDER.getDomain()), RECIPIENT1.asString()); Collection<MailAddress> result = testee.match(FakeMail.builder() .sender(SENDER) .recipient(RECIPIENT1) .build()); assertThat(result).isEmpty(); }