org.subethamail.smtp.RejectException Java Examples
The following examples show how to use
org.subethamail.smtp.RejectException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RejectOnFailedSpfCheck.java From mireka with Apache License 2.0 | 6 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectExceptionExt { SPFResult spfResult = spfChecker.getResult(); String spfResultCode = spfResult.getResult(); if (spfResultCode.equals(SPFErrorConstants.FAIL_CONV)) { String statusText; if (spfResult.getExplanation().isEmpty()) statusText = "Blocked by SPF"; else statusText = "Blocked - see: " + spfResult.getExplanation(); throw new RejectException(550, statusText); } else if (spfResult.equals(SPFErrorConstants.TEMP_ERROR_CONV)) { throw new RejectException(451, "Temporarily rejected: Problem on SPF lookup"); } else if (rejectOnPermanentError && spfResultCode.equals(SPFErrorConstants.PERM_ERROR_CONV)) { throw new RejectException(550, "Blocked - invalid SPF record"); } return chain.verifyRecipient(recipientContext); }
Example #2
Source File: ServerModeHiddenMailConfigIT.java From digdag with Apache License 2.0 | 6 votes |
@Override public AuthenticationHandler create() { return new AuthenticationHandler() { @Override public String auth(String clientInput) throws RejectException { auth.add(clientInput); throw new RejectException(); } @Override public Object getIdentity() { throw new AssertionError(); } }; }
Example #3
Source File: FilterChainMessageHandler.java From mireka with Apache License 2.0 | 5 votes |
private ReversePath convertToReversePath(String reversePath) throws RejectException { try { return new MailAddressFactory().createReversePath(reversePath); } catch (ParseException e) { logger.debug("Syntax error in reverse path " + reversePath, e); throw new RejectException(553, "Syntax error in reverse path " + reversePath); } }
Example #4
Source File: AcceptDomainPostmaster.java From mireka with Apache License 2.0 | 5 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { if (recipientContext.recipient.isDomainPostmaster()) return FilterReply.ACCEPT; return FilterReply.NEUTRAL; }
Example #5
Source File: AcceptGlobalPostmaster.java From mireka with Apache License 2.0 | 5 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { if (recipientContext.recipient.isGlobalPostmaster()) return FilterReply.ACCEPT; else return FilterReply.NEUTRAL; }
Example #6
Source File: AcceptPostmaster.java From mireka with Apache License 2.0 | 5 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { if (recipientContext.recipient.isPostmaster()) return FilterReply.ACCEPT; else return FilterReply.NEUTRAL; }
Example #7
Source File: AcceptRecipient.java From mireka with Apache License 2.0 | 5 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { if (recipientSpecification.isSatisfiedBy(recipientContext.recipient)) return FilterReply.ACCEPT; else return FilterReply.NEUTRAL; }
Example #8
Source File: ProhibitRelaying.java From mireka with Apache License 2.0 | 5 votes |
private FilterReply verifyRemotePartContainingRecipient( RemotePartContainingRecipient recipient) throws RejectException { RemotePart remotePart = recipient.getMailbox().getRemotePart(); for (RemotePartSpecification remotePartSpecification : localDomainSpecifications) { if (remotePartSpecification.isSatisfiedBy(remotePart)) return FilterReply.NEUTRAL; } throw new RejectException(550, "Relaying prohibited, user is not local (" + recipient + ")"); }
Example #9
Source File: ProhibitRelaying.java From mireka with Apache License 2.0 | 5 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { Recipient recipient = recipientContext.recipient; if (recipient instanceof GlobalPostmaster) return FilterReply.NEUTRAL; else if (recipient instanceof RemotePartContainingRecipient) return verifyRemotePartContainingRecipient((RemotePartContainingRecipient) recipient); else throw new IllegalArgumentException(); }
Example #10
Source File: TransmitterDestination.java From mireka with Apache License 2.0 | 5 votes |
@Override public void data(Mail mail) throws RejectExceptionExt { try { transmitter.transmit(mail); } catch (LocalMailSystemException e) { logger.warn("Cannot accept mail because of a " + "transmission failure", e); throw new RejectException(e.errorStatus().getSmtpReplyCode(), e .errorStatus().getMessagePrefixedWithEnhancedStatusCode()); } }
Example #11
Source File: ClientWithProxyErrorHandling.java From mireka with Apache License 2.0 | 5 votes |
private void sendDataStream(InputStream data) throws IOException, RejectException { byte[] buffer = new byte[8192]; int numRead; while ((numRead = data.read(buffer)) > 0) { try { smartClient.dataWrite(buffer, numRead); } catch (IOException e) { throw new RejectException(451, e.getMessage()); } } }
Example #12
Source File: FilterChainMessageHandler.java From mireka with Apache License 2.0 | 5 votes |
private Recipient convertToRecipient(String recipient) throws RejectException { try { return new MailAddressFactory().createRecipient(recipient); } catch (ParseException e) { logger.debug("Syntax error in recipient " + recipient, e); throw new RejectException(553, "Syntax error in mailbox name " + recipient); } }
Example #13
Source File: MockMessageHandler.java From james-project with Apache License 2.0 | 5 votes |
private MailAddress parse(String mailAddress) { try { return new MailAddress(mailAddress); } catch (AddressException e) { LOGGER.error("Error parsing mail address '{}'", mailAddress, e); throw new RejectException(SMTPStatusCode.SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501.getRawCode(), "invalid email address supplied"); } }
Example #14
Source File: MockMessageHandler.java From james-project with Apache License 2.0 | 5 votes |
private String readData(InputStream data) { try { return IOUtils.toString(data, StandardCharsets.UTF_8); } catch (IOException e) { LOGGER.error("Error reading data", e); throw new RejectException(SMTPStatusCode.SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501.getRawCode(), "invalid data supplied"); } }
Example #15
Source File: MockMessageHandler.java From james-project with Apache License 2.0 | 5 votes |
@Override public void behave(T input) throws RejectException { try { behavior1.behave(input); } finally { behavior2.behave(input); } }
Example #16
Source File: BackendClient.java From mireka with Apache License 2.0 | 5 votes |
public void connect() throws BackendRejectException, RejectException { try { client = new ClientWithProxyErrorHandling(backendServer); } catch (RejectException e) { exceptionAffectingConnection = e; throw e; } }
Example #17
Source File: RelayDestination.java From mireka with Apache License 2.0 | 5 votes |
private void initClient() { if (client != null) return; client = new BackendClient(backendServer); try { client.connect(); client.from(from.getSmtpText()); } catch (RejectException e) { logger.debug("Connection to backend server failed, " + "failed status is memorized, continuing..."); } }
Example #18
Source File: StopLoopTest.java From mireka with Apache License 2.0 | 5 votes |
@Test(expected = RejectException.class) public void testLoopingData() throws TooMuchDataException, RejectException, IOException { StopLoop stopLoop = new StopLoop(); stopLoop.setMaxReceivedHeaders(2); MailData bouncedMail = ExampleMailData.fromResource(getClass(), "looping.eml"); stopLoop.data(bouncedMail); }
Example #19
Source File: StopLoopTest.java From mireka with Apache License 2.0 | 5 votes |
@Test public void testNotLoopingData() throws TooMuchDataException, RejectException, IOException { StopLoop stopLoop = new StopLoop(); stopLoop.setMaxReceivedHeaders(2); stopLoop.data(ExampleMailData.simple()); }
Example #20
Source File: AwsSmtpRelay.java From aws-smtp-relay with GNU Lesser General Public License v3.0 | 5 votes |
public void deliver(String from, String to, InputStream inputStream) throws IOException { AmazonSimpleEmailService client; if (cmd.hasOption("r")) { client = AmazonSimpleEmailServiceClientBuilder.standard().withRegion(cmd.getOptionValue("r")).build(); } else { client = AmazonSimpleEmailServiceClientBuilder.standard().build(); } byte[] msg = IOUtils.toByteArray(inputStream); RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(msg)); SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage).withSource(from) .withDestinations(to); if (cmd.hasOption("a")) { rawEmailRequest = rawEmailRequest.withSourceArn(cmd.getOptionValue("a")); } if (cmd.hasOption("f")) { rawEmailRequest = rawEmailRequest.withFromArn(cmd.getOptionValue("f")); } if (cmd.hasOption("t")) { rawEmailRequest = rawEmailRequest.withReturnPathArn(cmd.getOptionValue("t")); } if (cmd.hasOption("c")) { rawEmailRequest = rawEmailRequest.withConfigurationSetName(cmd.getOptionValue("c")); } try { client.sendRawEmail(rawEmailRequest); } catch (AmazonSimpleEmailServiceException e) { if(e.getErrorType() == ErrorType.Client) { // If it's a client error, return a permanent error throw new RejectException(e.getMessage()); } else { throw new RejectException(451, e.getMessage()); } } }
Example #21
Source File: SMTPTestWiser.java From vertx-mail-client with Apache License 2.0 | 5 votes |
protected void startSMTP(String factory) { wiser = new Wiser(); wiser.setPort(1587); wiser.getServer().setAuthenticationHandlerFactory(new AuthenticationHandlerFactory() { /* * AUTH PLAIN handler which returns success on any string */ @Override public List<String> getAuthenticationMechanisms() { return Arrays.asList("PLAIN"); } @Override public AuthenticationHandler create() { return new AuthenticationHandler() { @Override public String auth(final String clientInput) throws RejectException { log.info(clientInput); return null; } @Override public Object getIdentity() { return "username"; } }; } }); Security.setProperty("ssl.SocketFactory.provider", factory); wiser.getServer().setEnableTLS(true); wiser.start(); }
Example #22
Source File: MockAuthenticationHandler.java From entando-components with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String auth(String paramString) throws RejectException { return ""; }
Example #23
Source File: ClientWithProxyErrorHandling.java From mireka with Apache License 2.0 | 4 votes |
public ClientWithProxyErrorHandling(BackendServer backend) throws BackendRejectException, RejectException { this.backend = backend; this.smartClient = connect(); }
Example #24
Source File: AcceptAllRecipient.java From mireka with Apache License 2.0 | 4 votes |
@Override public FilterReply verifyRecipient(RecipientContext recipientContext) throws RejectException { return FilterReply.ACCEPT; }
Example #25
Source File: ChainEnd.java From mireka with Apache License 2.0 | 4 votes |
@Override public void recipient(RecipientContext recipientContext) throws RejectException { // do nothing }
Example #26
Source File: MockMessageHandler.java From james-project with Apache License 2.0 | 4 votes |
@Override public void behave(T input) throws RejectException { Response response = behavior.getResponse(); LOGGER.info("Applying behavior {}", behavior); throw new RejectException(response.getCode().getRawCode(), response.getMessage()); }
Example #27
Source File: TestUtils.java From digdag with Apache License 2.0 | 4 votes |
public static Wiser startMailServer(String hostname, String user, String password) { AuthenticationHandlerFactory authenticationHandlerFactory = new AuthenticationHandlerFactory() { @Override public List<String> getAuthenticationMechanisms() { return ImmutableList.of("PLAIN"); } @Override public AuthenticationHandler create() { return new AuthenticationHandler() { private String identity; @Override public String auth(String clientInput) throws RejectException { String prefix = "AUTH PLAIN "; if (!clientInput.startsWith(prefix)) { throw new RejectException(); } String credentialsBase64 = clientInput.substring(prefix.length()); byte[] credentials = Base64.getDecoder().decode(credentialsBase64); // [authzid] UTF8NUL authcid UTF8NUL passwd byte[] expectedCredentials = concat( user.getBytes(UTF_8), new byte[] {0}, user.getBytes(UTF_8), new byte[] {0}, password.getBytes(UTF_8) ); if (!Arrays.equals(credentials, expectedCredentials)) { throw new RejectException(); } this.identity = user; return null; } @Override public Object getIdentity() { return identity; } }; } }; return startMailServer(hostname, authenticationHandlerFactory); }
Example #28
Source File: AuthCommand.java From subethasmtp with Apache License 2.0 | 4 votes |
/** */ @Override public void execute(String commandString, Session sess) throws IOException { if (sess.isAuthenticated()) { sess.sendResponse("503 Refusing any other AUTH command."); return; } AuthenticationHandlerFactory authFactory = sess.getServer().getAuthenticationHandlerFactory(); if (authFactory == null) { sess.sendResponse("502 Authentication not supported"); return; } AuthenticationHandler authHandler = authFactory.create(); String[] args = this.getArgs(commandString); // Let's check the command syntax if (args.length < 2) { sess.sendResponse("501 Syntax: " + VERB + " mechanism [initial-response]"); return; } // Let's check if we support the required authentication mechanism String mechanism = args[1]; if (!authFactory.getAuthenticationMechanisms().contains(mechanism.toUpperCase(Locale.ENGLISH))) { sess.sendResponse("504 The requested authentication mechanism is not supported"); return; } // OK, let's go trough the authentication process. try { // The authentication process may require a series of challenge-responses CRLFTerminatedReader reader = sess.getReader(); String response = authHandler.auth(commandString); if (response != null) { // challenge-response iteration sess.sendResponse(response); } while (response != null) { String clientInput = reader.readLine(); if (clientInput.trim().equals(AUTH_CANCEL_COMMAND)) { // RFC 2554 explicitly states this: sess.sendResponse("501 Authentication canceled by client."); return; } else { response = authHandler.auth(clientInput); if (response != null) { // challenge-response iteration sess.sendResponse(response); } } } sess.sendResponse("235 Authentication successful."); sess.setAuthenticationHandler(authHandler); } catch (RejectException authFailed) { sess.sendResponse(authFailed.getErrorResponse()); } }
Example #29
Source File: PlainAuthenticationHandlerFactory.java From subethasmtp with Apache License 2.0 | 4 votes |
public String auth(String clientInput) throws RejectException { StringTokenizer stk = new StringTokenizer(clientInput); String secret = stk.nextToken(); if (secret.trim().equalsIgnoreCase("AUTH")) { // Let's read the RFC2554 "initial-response" parameter // The line could be in the form of "AUTH PLAIN <base64Secret>" if (!stk.nextToken().trim().equalsIgnoreCase("PLAIN")) { // Mechanism mismatch throw new RejectException(504, "AUTH mechanism mismatch"); } if (stk.hasMoreTokens()) { // the client submitted an initial response secret = stk.nextToken(); } else { // the client did not submit an initial response, we'll get it in the next pass return "334 Ok"; } } byte[] decodedSecret = Base64.decode(secret); if (decodedSecret == null) throw new RejectException(501, /*5.5.4*/ "Invalid command argument, not a valid Base64 string"); /* * RFC4616: The client presents the authorization identity (identity * to act as), followed by a NUL (U+0000) character, followed by the * authentication identity (identity whose password will be used), * followed by a NUL (U+0000) character, followed by the clear-text * password. */ int i, j; for (i = 0; i < decodedSecret.length && decodedSecret[i] != 0; i++) ; if (i >= decodedSecret.length) { throw new RejectException(501, /*5.5.4*/ "Invalid command argument, does not contain NUL"); } for (j = i + 1; j < decodedSecret.length && decodedSecret[j] != 0; j++) ; if (j >= decodedSecret.length) { throw new RejectException(501, /*5.5.4*/ "Invalid command argument, does not contain the second NUL"); } @SuppressWarnings("unused") String authorizationId = new String(decodedSecret, 0, i); String authenticationId = new String(decodedSecret, i + 1, j - i - 1); String passwd = new String(decodedSecret, j + 1, decodedSecret.length - j - 1); // might be nice to do something with authorizationId, but for // purposes of the UsernamePasswordValidator, we just want to use // authenticationId this.username = authenticationId; this.password = passwd; try { PlainAuthenticationHandlerFactory.this.helper.login(this.username.toString(), this.password); } catch (LoginFailedException lfe) { throw new RejectException(535, /*5.7.8*/ "Authentication credentials invalid"); } return null; }
Example #30
Source File: RejectExceptionExt.java From mireka with Apache License 2.0 | 2 votes |
/** * Converts this exception to a SubEthaSMTP {@link RejectException}. * * @return the {@link RejectException} corresponding to this exception. */ public RejectException toRejectException() { return new RejectException(reply.getSmtpReplyCode(), reply.getMessagePrefixedWithEnhancedStatusCode()); }