Extract classes
This commit is contained in:
parent
0b22cd5b8f
commit
7f7a8902a9
7 changed files with 176 additions and 164 deletions
|
@ -0,0 +1,17 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
class EnhancedNegativeSmtpReplyException extends NegativeSmtpReplyException {
|
||||
|
||||
private final SmtpEnhancedStatusCodeClass escClass;
|
||||
private final SmtpEnhancedStatusCodeSubject escSubject;
|
||||
private final SmtpEnhancedStatusCodeDetail escDetail;
|
||||
|
||||
public EnhancedNegativeSmtpReplyException(int replyCode, SmtpEnhancedStatusCodeClass escClass,
|
||||
SmtpEnhancedStatusCodeSubject escSubject, SmtpEnhancedStatusCodeDetail escDetail, String replyText) {
|
||||
super(replyCode, replyText);
|
||||
this.escClass = escClass;
|
||||
this.escSubject = escSubject;
|
||||
this.escDetail = escDetail;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
|
||||
|
||||
/**
|
||||
* Exception that is thrown when the server sends a negative reply (reply codes 4xx or 5xx).
|
||||
*/
|
||||
class NegativeSmtpReplyException extends MessagingException {
|
||||
private static final long serialVersionUID = 8696043577357897135L;
|
||||
|
||||
private final int mReplyCode;
|
||||
private final String mReplyText;
|
||||
|
||||
public NegativeSmtpReplyException(int replyCode, String replyText) {
|
||||
super((replyText != null && !replyText.isEmpty()) ?
|
||||
replyText : ("Negative SMTP reply: " + replyCode),
|
||||
isPermanentSmtpError(replyCode));
|
||||
mReplyCode = replyCode;
|
||||
mReplyText = replyText;
|
||||
}
|
||||
|
||||
private static boolean isPermanentSmtpError(int replyCode) {
|
||||
return replyCode >= 500 && replyCode <= 599;
|
||||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return mReplyCode;
|
||||
}
|
||||
|
||||
public String getReplyText() {
|
||||
return mReplyText;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum SmtpEnhancedStatusCodeClass {
|
||||
Success(2), PersistentTransientFailure(4), PermanentFailure(5);
|
||||
|
||||
private final int codeClass;
|
||||
|
||||
public static SmtpEnhancedStatusCodeClass parse(String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeClass classEnum: SmtpEnhancedStatusCodeClass.values()) {
|
||||
if (classEnum.codeClass == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
SmtpEnhancedStatusCodeClass(int codeClass) {
|
||||
this.codeClass = codeClass;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum SmtpEnhancedStatusCodeDetail {
|
||||
Undefined(SmtpEnhancedStatusCodeSubject.Undefined, 0),
|
||||
OtherAddressStatus(SmtpEnhancedStatusCodeSubject.Addressing, 0),
|
||||
BadDestinationMailboxAddress(SmtpEnhancedStatusCodeSubject.Addressing, 1),
|
||||
BadDestinationSystemAddress(SmtpEnhancedStatusCodeSubject.Addressing, 2),
|
||||
BadDestinationMailboxAddressSyntax(SmtpEnhancedStatusCodeSubject.Addressing, 3),
|
||||
DestinationMailboxAddressAmbiguous(SmtpEnhancedStatusCodeSubject.Addressing, 4),
|
||||
DestinationAddressValid(SmtpEnhancedStatusCodeSubject.Addressing, 5),
|
||||
DestinationMailboxMoved(SmtpEnhancedStatusCodeSubject.Addressing, 6),
|
||||
BadSenderMailboxSyntax(SmtpEnhancedStatusCodeSubject.Addressing, 7),
|
||||
BadSenderSystemAddress(SmtpEnhancedStatusCodeSubject.Addressing, 8),
|
||||
|
||||
OtherMailboxStatus(SmtpEnhancedStatusCodeSubject.Mailbox,0),
|
||||
MailboxDisabled(SmtpEnhancedStatusCodeSubject.Mailbox,1),
|
||||
MailboxFull(SmtpEnhancedStatusCodeSubject.Mailbox,2),
|
||||
MessageLengthExceeded(SmtpEnhancedStatusCodeSubject.Mailbox,3),
|
||||
MailingListExpansionProblem(SmtpEnhancedStatusCodeSubject.Mailbox,4),
|
||||
|
||||
OtherMailSystemStatus(SmtpEnhancedStatusCodeSubject.MailSystem,0),
|
||||
MailSystemFull(SmtpEnhancedStatusCodeSubject.MailSystem,1),
|
||||
SystemNotAcceptingMessages(SmtpEnhancedStatusCodeSubject.MailSystem,2),
|
||||
SystemIncapableOfFeature(SmtpEnhancedStatusCodeSubject.MailSystem,3),
|
||||
MessageTooBig(SmtpEnhancedStatusCodeSubject.MailSystem,4),
|
||||
SystemIncorrectlyConfigured(SmtpEnhancedStatusCodeSubject.MailSystem,5),
|
||||
|
||||
OtherNetworkRouting(SmtpEnhancedStatusCodeSubject.NetworkRouting,0),
|
||||
NoAnswerFromHost(SmtpEnhancedStatusCodeSubject.NetworkRouting,1),
|
||||
BadConnection(SmtpEnhancedStatusCodeSubject.NetworkRouting,2),
|
||||
DirectoryServerFailure(SmtpEnhancedStatusCodeSubject.NetworkRouting,3),
|
||||
UnableToRoute(SmtpEnhancedStatusCodeSubject.NetworkRouting,4),
|
||||
MailSystemCongestion(SmtpEnhancedStatusCodeSubject.NetworkRouting,5),
|
||||
RoutingLoopDetected(SmtpEnhancedStatusCodeSubject.NetworkRouting,6),
|
||||
DeliveryTimeExpired(SmtpEnhancedStatusCodeSubject.NetworkRouting,7),
|
||||
|
||||
OtherMailDeliveryProtocol(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,0),
|
||||
InvalidCommand(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,1),
|
||||
SyntaxError(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,2),
|
||||
TooManyRecipients(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,3),
|
||||
InvalidCommandArguments(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,4),
|
||||
WrongProtocolVersion(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,5),
|
||||
|
||||
OtherMessageContentOrMedia(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,0),
|
||||
MediaNotSupported(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,1),
|
||||
ConversionRequiredAndProhibited(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,2),
|
||||
ConversionRequiredButUnsupported(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,3),
|
||||
ConversionWithLossPerformed(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,4),
|
||||
ConversionFailed(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,5),
|
||||
|
||||
OtherSecurityOrPolicyStatus(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 0),
|
||||
DeliveryNotAuthorized(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 1),
|
||||
MailingListExpansionProhibited(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 2),
|
||||
SecurityConversionRequired(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 3),
|
||||
SecurityFeaturesUnsupported(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 4),
|
||||
CryptographicFailure(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 5),
|
||||
CryptographicAlgorithmUnsupported(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 6),
|
||||
MessageIntegrityFailure(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 7);
|
||||
|
||||
private final SmtpEnhancedStatusCodeSubject subject;
|
||||
private final int detail;
|
||||
|
||||
SmtpEnhancedStatusCodeDetail(SmtpEnhancedStatusCodeSubject subject, int detail) {
|
||||
this.subject = subject;
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public static SmtpEnhancedStatusCodeDetail parse(SmtpEnhancedStatusCodeSubject subject, String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeDetail detailEnum: SmtpEnhancedStatusCodeDetail.values()) {
|
||||
if (detailEnum.subject == subject && detailEnum.detail == value) {
|
||||
return detailEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum SmtpEnhancedStatusCodeSubject {
|
||||
Undefined(0), Addressing(1), Mailbox(2), MailSystem(3), NetworkRouting(4),
|
||||
MailDeliveryProtocol(5), MessageContentOrMedia(6), SecurityOrPolicyStatus(7);
|
||||
|
||||
private final int codeSubject;
|
||||
|
||||
public static SmtpEnhancedStatusCodeSubject parse(String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeSubject classEnum: SmtpEnhancedStatusCodeSubject.values()) {
|
||||
if (classEnum.codeSubject == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
SmtpEnhancedStatusCodeSubject(int codeSubject) {
|
||||
this.codeSubject = codeSubject;
|
||||
}
|
||||
}
|
|
@ -899,166 +899,4 @@ public class SmtpTransport extends Transport {
|
|||
protected String getCanonicalHostName(InetAddress localAddress) {
|
||||
return localAddress.getCanonicalHostName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that is thrown when the server sends a negative reply (reply codes 4xx or 5xx).
|
||||
*/
|
||||
static class NegativeSmtpReplyException extends MessagingException {
|
||||
private static final long serialVersionUID = 8696043577357897135L;
|
||||
|
||||
private final int mReplyCode;
|
||||
private final String mReplyText;
|
||||
|
||||
public NegativeSmtpReplyException(int replyCode, String replyText) {
|
||||
super((replyText != null && !replyText.isEmpty()) ?
|
||||
replyText : ("Negative SMTP reply: " + replyCode),
|
||||
isPermanentSmtpError(replyCode));
|
||||
mReplyCode = replyCode;
|
||||
mReplyText = replyText;
|
||||
}
|
||||
|
||||
private static boolean isPermanentSmtpError(int replyCode) {
|
||||
return replyCode >= 500 && replyCode <= 599;
|
||||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return mReplyCode;
|
||||
}
|
||||
|
||||
public String getReplyText() {
|
||||
return mReplyText;
|
||||
}
|
||||
}
|
||||
|
||||
static class EnhancedNegativeSmtpReplyException extends NegativeSmtpReplyException {
|
||||
|
||||
private final SmtpEnhancedStatusCodeClass escClass;
|
||||
private final SmtpEnhancedStatusCodeSubject escSubject;
|
||||
private final SmtpEnhancedStatusCodeDetail escDetail;
|
||||
|
||||
public EnhancedNegativeSmtpReplyException(int replyCode, SmtpEnhancedStatusCodeClass escClass,
|
||||
SmtpEnhancedStatusCodeSubject escSubject, SmtpEnhancedStatusCodeDetail escDetail, String replyText) {
|
||||
super(replyCode, replyText);
|
||||
this.escClass = escClass;
|
||||
this.escSubject = escSubject;
|
||||
this.escDetail = escDetail;
|
||||
}
|
||||
}
|
||||
|
||||
enum SmtpEnhancedStatusCodeClass {
|
||||
Success(2), PersistentTransientFailure(4), PermanentFailure(5);
|
||||
|
||||
private final int codeClass;
|
||||
|
||||
public static SmtpEnhancedStatusCodeClass parse(String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeClass classEnum: SmtpEnhancedStatusCodeClass.values()) {
|
||||
if (classEnum.codeClass == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
SmtpEnhancedStatusCodeClass(int codeClass) {
|
||||
this.codeClass = codeClass;
|
||||
}
|
||||
}
|
||||
|
||||
enum SmtpEnhancedStatusCodeSubject {
|
||||
Undefined(0), Addressing(1), Mailbox(2), MailSystem(3), NetworkRouting(4),
|
||||
MailDeliveryProtocol(5), MessageContentOrMedia(6), SecurityOrPolicyStatus(7);
|
||||
|
||||
private final int codeSubject;
|
||||
|
||||
public static SmtpEnhancedStatusCodeSubject parse(String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeSubject classEnum: SmtpEnhancedStatusCodeSubject.values()) {
|
||||
if (classEnum.codeSubject == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
SmtpEnhancedStatusCodeSubject(int codeSubject) {
|
||||
this.codeSubject = codeSubject;
|
||||
}
|
||||
}
|
||||
|
||||
enum SmtpEnhancedStatusCodeDetail {
|
||||
Undefined(SmtpEnhancedStatusCodeSubject.Undefined, 0),
|
||||
OtherAddressStatus(SmtpEnhancedStatusCodeSubject.Addressing, 0),
|
||||
BadDestinationMailboxAddress(SmtpEnhancedStatusCodeSubject.Addressing, 1),
|
||||
BadDestinationSystemAddress(SmtpEnhancedStatusCodeSubject.Addressing, 2),
|
||||
BadDestinationMailboxAddressSyntax(SmtpEnhancedStatusCodeSubject.Addressing, 3),
|
||||
DestinationMailboxAddressAmbiguous(SmtpEnhancedStatusCodeSubject.Addressing, 4),
|
||||
DestinationAddressValid(SmtpEnhancedStatusCodeSubject.Addressing, 5),
|
||||
DestinationMailboxMoved(SmtpEnhancedStatusCodeSubject.Addressing, 6),
|
||||
BadSenderMailboxSyntax(SmtpEnhancedStatusCodeSubject.Addressing, 7),
|
||||
BadSenderSystemAddress(SmtpEnhancedStatusCodeSubject.Addressing, 8),
|
||||
|
||||
OtherMailboxStatus(SmtpEnhancedStatusCodeSubject.Mailbox,0),
|
||||
MailboxDisabled(SmtpEnhancedStatusCodeSubject.Mailbox,1),
|
||||
MailboxFull(SmtpEnhancedStatusCodeSubject.Mailbox,2),
|
||||
MessageLengthExceeded(SmtpEnhancedStatusCodeSubject.Mailbox,3),
|
||||
MailingListExpansionProblem(SmtpEnhancedStatusCodeSubject.Mailbox,4),
|
||||
|
||||
OtherMailSystemStatus(SmtpEnhancedStatusCodeSubject.MailSystem,0),
|
||||
MailSystemFull(SmtpEnhancedStatusCodeSubject.MailSystem,1),
|
||||
SystemNotAcceptingMessages(SmtpEnhancedStatusCodeSubject.MailSystem,2),
|
||||
SystemIncapableOfFeature(SmtpEnhancedStatusCodeSubject.MailSystem,3),
|
||||
MessageTooBig(SmtpEnhancedStatusCodeSubject.MailSystem,4),
|
||||
SystemIncorrectlyConfigured(SmtpEnhancedStatusCodeSubject.MailSystem,5),
|
||||
|
||||
OtherNetworkRouting(SmtpEnhancedStatusCodeSubject.NetworkRouting,0),
|
||||
NoAnswerFromHost(SmtpEnhancedStatusCodeSubject.NetworkRouting,1),
|
||||
BadConnection(SmtpEnhancedStatusCodeSubject.NetworkRouting,2),
|
||||
DirectoryServerFailure(SmtpEnhancedStatusCodeSubject.NetworkRouting,3),
|
||||
UnableToRoute(SmtpEnhancedStatusCodeSubject.NetworkRouting,4),
|
||||
MailSystemCongestion(SmtpEnhancedStatusCodeSubject.NetworkRouting,5),
|
||||
RoutingLoopDetected(SmtpEnhancedStatusCodeSubject.NetworkRouting,6),
|
||||
DeliveryTimeExpired(SmtpEnhancedStatusCodeSubject.NetworkRouting,7),
|
||||
|
||||
OtherMailDeliveryProtocol(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,0),
|
||||
InvalidCommand(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,1),
|
||||
SyntaxError(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,2),
|
||||
TooManyRecipients(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,3),
|
||||
InvalidCommandArguments(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,4),
|
||||
WrongProtocolVersion(SmtpEnhancedStatusCodeSubject.MailDeliveryProtocol,5),
|
||||
|
||||
OtherMessageContentOrMedia(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,0),
|
||||
MediaNotSupported(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,1),
|
||||
ConversionRequiredAndProhibited(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,2),
|
||||
ConversionRequiredButUnsupported(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,3),
|
||||
ConversionWithLossPerformed(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,4),
|
||||
ConversionFailed(SmtpEnhancedStatusCodeSubject.MessageContentOrMedia,5),
|
||||
|
||||
OtherSecurityOrPolicyStatus(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 0),
|
||||
DeliveryNotAuthorized(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 1),
|
||||
MailingListExpansionProhibited(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 2),
|
||||
SecurityConversionRequired(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 3),
|
||||
SecurityFeaturesUnsupported(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 4),
|
||||
CryptographicFailure(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 5),
|
||||
CryptographicAlgorithmUnsupported(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 6),
|
||||
MessageIntegrityFailure(SmtpEnhancedStatusCodeSubject.SecurityOrPolicyStatus, 7);
|
||||
|
||||
private final SmtpEnhancedStatusCodeSubject subject;
|
||||
private final int detail;
|
||||
|
||||
SmtpEnhancedStatusCodeDetail(SmtpEnhancedStatusCodeSubject subject, int detail) {
|
||||
this.subject = subject;
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public static SmtpEnhancedStatusCodeDetail parse(SmtpEnhancedStatusCodeSubject subject, String s) {
|
||||
int value = Integer.parseInt(s);
|
||||
for (SmtpEnhancedStatusCodeDetail detailEnum: SmtpEnhancedStatusCodeDetail.values()) {
|
||||
if (detailEnum.subject == subject && detailEnum.detail == value) {
|
||||
return detailEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
|
|||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
import com.fsck.k9.mail.transport.mockServer.MockSmtpServer;
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransport;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -680,7 +679,7 @@ public class SmtpTransportTest {
|
|||
try {
|
||||
transport.sendMessage(message);
|
||||
fail("Expected exception");
|
||||
} catch (SmtpTransport.NegativeSmtpReplyException e) {
|
||||
} catch (NegativeSmtpReplyException e) {
|
||||
assertEquals(421, e.getReplyCode());
|
||||
assertEquals("4.7.0 Temporary system problem", e.getReplyText());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue