/** * Returns the user part. * * @return the user part of this email address * @deprecated use {@link #getLocalPart()}, whose name was changed to * align with the RFC2822 3.4.1. addr-spec specification */ @Deprecated public String getUser() { return getLocalPart(); }
/** * Returns the user part. * * @return the user part of this email address * @deprecated use {@link #getLocalPart()}, whose name was changed to * align with the RFC2822 3.4.1. addr-spec specification */ @Deprecated public String getUser() { return getLocalPart(); }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (rcpt.getLocalPart().equalsIgnoreCase("postmaster") || rcpt.getLocalPart().equalsIgnoreCase("abuse")) { LOGGER.debug("Sender allowed"); return HookResult.OK; } else { return HookResult.DECLINED; } }
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())); }
/** * Map any virtual recipients to real recipients using the configured * mapping. * * @param recipientsMap * the mapping of virtual to real recipients */ @Override protected void mapRecipients(Map<MailAddress, String> recipientsMap) { Collection<MailAddress> recipients = recipientsMap.keySet(); for (MailAddress source : recipients) { String user = source.getLocalPart().toLowerCase(Locale.US); Domain domain = source.getDomain(); String targetString = RecipientRewriteTableUtil.getTargetString(user, domain, mappings); if (targetString != null) { recipientsMap.put(source, targetString); } } }
@Override public String getUser(MailAddress mailAddress) throws UsersRepositoryException { if (supportVirtualHosting()) { return mailAddress.asString(); } else { return mailAddress.getLocalPart(); } }
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 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 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(); } }
@DELETE @Path(ROOT_PATH + "/{" + FORWARD_BASE_ADDRESS + "}/targets/{" + FORWARD_DESTINATION_ADDRESS + "}") @ApiOperation(value = "remove a destination address from a forward") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = FORWARD_BASE_ADDRESS, paramType = "path"), @ApiImplicitParam(required = true, dataType = "string", name = FORWARD_DESTINATION_ADDRESS, paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = FORWARD_BASE_ADDRESS + " or forward structure format is not valid"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public HaltException removeFromForwardDestination(Request request, Response response) throws JsonExtractException, AddressException, RecipientRewriteTableException { MailAddress baseAddress = parseMailAddress(request.params(FORWARD_BASE_ADDRESS)); MailAddress destinationAddressToBeRemoved = parseMailAddress(request.params(FORWARD_DESTINATION_ADDRESS)); MappingSource source = MappingSource.fromUser(User.fromLocalPartWithDomain(baseAddress.getLocalPart(), baseAddress.getDomain())); recipientRewriteTable.removeForwardMapping(source, destinationAddressToBeRemoved.asString()); return halt(HttpStatus.NO_CONTENT_204); }
/** * Test method for {@link MailAddress#getLocalPart()}. */ @Test public void testGetLocalPart() { try { MailAddress a = new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART)); assertThat(a.getLocalPart()).isEqualTo(GOOD_LOCAL_PART); } catch (AddressException e) { System.out.println("AddressException" + e.getMessage()); assertThat(false).describedAs(e.getMessage()).isTrue(); } }
@Test public void storeMailShouldUseLocalPartWhenSupportsVirtualHosting() throws Exception { MailAddress recipient = MailAddressFixture.OTHER_AT_JAMES; when(usersRepository.getUser(recipient)).thenReturn(recipient.getLocalPart()); FakeMail mail = FakeMail.builder() .mimeMessage(mimeMessage) .build(); testee.storeMail(recipient, mail); verify(mailboxAppender).append(any(MimeMessage.class), eq(recipient.getLocalPart()), eq(FOLDER)); }
/** * Test method for {@link MailAddress#getLocalPart()}. */ @Test public void testGetLocalPart() { try { MailAddress a = new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART)); assertThat(a.getLocalPart()).isEqualTo(GOOD_LOCAL_PART); } catch (AddressException e) { System.out.println("AddressException" + e.getMessage()); assertThat(false).describedAs(e.getMessage()).isTrue(); } }
@DELETE @Path(ROOT_PATH + "/{" + GROUP_ADDRESS + "}/{" + USER_ADDRESS + "}") @ApiOperation(value = "remove a member from a group") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = GROUP_ADDRESS, paramType = "path"), @ApiImplicitParam(required = true, dataType = "string", name = USER_ADDRESS, paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = GROUP_ADDRESS + " or group structure format is not valid"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public HaltException removeFromGroup(Request request, Response response) throws RecipientRewriteTableException { MailAddress groupAddress = parseMailAddress(request.params(GROUP_ADDRESS)); MailAddress userAddress = parseMailAddress(request.params(USER_ADDRESS)); MappingSource source = MappingSource .fromUser( User.fromLocalPartWithDomain(groupAddress.getLocalPart(), groupAddress.getDomain())); recipientRewriteTable.removeGroupMapping(source, userAddress.asString()); return halt(HttpStatus.NO_CONTENT_204); }
@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(); }
@Before public void setUp() throws Exception { mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver()); quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory()); maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); CurrentQuotaCalculator quotaCalculator = new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver); InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(quotaCalculator, mailboxManager); StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager); usersRepository = mock(UsersRepository.class); testee = new IsOverQuota(quotaRootResolver, quotaManager, mailboxManager, usersRepository); mailboxManager.setQuotaRootResolver(quotaRootResolver); mailboxManager.setQuotaManager(quotaManager); testee.init(FakeMatcherConfig.builder().matcherName("IsOverQuota").build()); when(usersRepository.getUser(MailAddressFixture.ANY_AT_JAMES)).thenReturn(MailAddressFixture.ANY_AT_JAMES.getLocalPart()); when(usersRepository.getUser(MailAddressFixture.OTHER_AT_JAMES)).thenReturn(MailAddressFixture.OTHER_AT_JAMES.getLocalPart()); }
@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(); }
@Test public void matchShouldNotIncludeRecipientNotOverQuota() throws Exception { String username = MailAddressFixture.ANY_AT_JAMES.getLocalPart(); QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(MailboxPath.inbox(mailboxManager.createSystemSession(username))); maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(100)); FakeMail fakeMail = FakeMail.builder() .recipient(MailAddressFixture.ANY_AT_JAMES) .recipient(MailAddressFixture.OTHER_AT_JAMES) .size(150) .build(); Collection<MailAddress> result = testee.match(fakeMail); assertThat(result).containsOnly(MailAddressFixture.ANY_AT_JAMES); }