Code cleanup
This commit is contained in:
parent
7f7a8902a9
commit
188720d7ff
9 changed files with 171 additions and 149 deletions
|
@ -2,16 +2,17 @@ package com.fsck.k9.mail.transport.smtp;
|
|||
|
||||
|
||||
class EnhancedNegativeSmtpReplyException extends NegativeSmtpReplyException {
|
||||
private final StatusCodeClass statusCodeClass;
|
||||
private final StatusCodeSubject statusCodeSubject;
|
||||
private final StatusCodeDetail statusCodeDetail;
|
||||
|
||||
private final SmtpEnhancedStatusCodeClass escClass;
|
||||
private final SmtpEnhancedStatusCodeSubject escSubject;
|
||||
private final SmtpEnhancedStatusCodeDetail escDetail;
|
||||
|
||||
public EnhancedNegativeSmtpReplyException(int replyCode, SmtpEnhancedStatusCodeClass escClass,
|
||||
SmtpEnhancedStatusCodeSubject escSubject, SmtpEnhancedStatusCodeDetail escDetail, String replyText) {
|
||||
EnhancedNegativeSmtpReplyException(int replyCode, StatusCodeClass statusCodeClass,
|
||||
StatusCodeSubject statusCodeSubject, StatusCodeDetail statusCodeDetail,
|
||||
String replyText) {
|
||||
super(replyCode, replyText);
|
||||
this.escClass = escClass;
|
||||
this.escSubject = escSubject;
|
||||
this.escDetail = escDetail;
|
||||
this.statusCodeClass = statusCodeClass;
|
||||
this.statusCodeSubject = statusCodeSubject;
|
||||
this.statusCodeDetail = statusCodeDetail;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
|
||||
|
||||
|
@ -10,15 +12,19 @@ import com.fsck.k9.mail.MessagingException;
|
|||
class NegativeSmtpReplyException extends MessagingException {
|
||||
private static final long serialVersionUID = 8696043577357897135L;
|
||||
|
||||
private final int mReplyCode;
|
||||
private final String mReplyText;
|
||||
|
||||
private final int replyCode;
|
||||
private final String replyText;
|
||||
|
||||
|
||||
public NegativeSmtpReplyException(int replyCode, String replyText) {
|
||||
super((replyText != null && !replyText.isEmpty()) ?
|
||||
replyText : ("Negative SMTP reply: " + replyCode),
|
||||
isPermanentSmtpError(replyCode));
|
||||
mReplyCode = replyCode;
|
||||
mReplyText = replyText;
|
||||
super(buildErrorMessage(replyCode, replyText), isPermanentSmtpError(replyCode));
|
||||
this.replyCode = replyCode;
|
||||
this.replyText = replyText;
|
||||
}
|
||||
|
||||
private static String buildErrorMessage(int replyCode, String replyText) {
|
||||
return TextUtils.isEmpty(replyText) ? "Negative SMTP reply: " + replyCode : replyText;
|
||||
}
|
||||
|
||||
private static boolean isPermanentSmtpError(int replyCode) {
|
||||
|
@ -26,10 +32,10 @@ class NegativeSmtpReplyException extends MessagingException {
|
|||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return mReplyCode;
|
||||
return replyCode;
|
||||
}
|
||||
|
||||
public String getReplyText() {
|
||||
return mReplyText;
|
||||
return replyText;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -712,23 +712,24 @@ public class SmtpTransport extends Transport {
|
|||
}
|
||||
|
||||
private MessagingException buildEnhancedNegativeSmtpReplyException(int replyCode, List<String> results) {
|
||||
SmtpEnhancedStatusCodeClass escClass = null;
|
||||
SmtpEnhancedStatusCodeSubject escSubject = null;
|
||||
SmtpEnhancedStatusCodeDetail escDetail = null;
|
||||
StatusCodeClass statusCodeClass = null;
|
||||
StatusCodeSubject statusCodeSubject = null;
|
||||
StatusCodeDetail statusCodeDetail = null;
|
||||
|
||||
String message = "";
|
||||
for (String resultLine: results) {
|
||||
for (String resultLine : results) {
|
||||
message += resultLine.split(" ", 2)[1] + " ";
|
||||
}
|
||||
if (results.size() > 0) {
|
||||
String[] esc = results.get(0).split(" ", 2)[0].split("\\.");
|
||||
String[] statusCodeParts = results.get(0).split(" ", 2)[0].split("\\.");
|
||||
|
||||
escClass = SmtpEnhancedStatusCodeClass.parse(esc[0]);
|
||||
escSubject = SmtpEnhancedStatusCodeSubject.parse(esc[1]);
|
||||
escDetail = SmtpEnhancedStatusCodeDetail.parse(escSubject, esc[2]);
|
||||
statusCodeClass = StatusCodeClass.parse(statusCodeParts[0]);
|
||||
statusCodeSubject = StatusCodeSubject.parse(statusCodeParts[1]);
|
||||
statusCodeDetail = StatusCodeDetail.parse(statusCodeSubject, statusCodeParts[2]);
|
||||
}
|
||||
|
||||
return new EnhancedNegativeSmtpReplyException(replyCode, escClass, escSubject, escDetail, message.trim());
|
||||
return new EnhancedNegativeSmtpReplyException(replyCode, statusCodeClass, statusCodeSubject, statusCodeDetail,
|
||||
message.trim());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum StatusCodeClass {
|
||||
SUCCESS(2),
|
||||
PERSISTENT_TRANSIENT_FAILURE(4),
|
||||
PERMANENT_FAILURE(5);
|
||||
|
||||
|
||||
private final int codeClass;
|
||||
|
||||
|
||||
static StatusCodeClass parse(String statusCodeClassString) {
|
||||
int value = Integer.parseInt(statusCodeClassString);
|
||||
for (StatusCodeClass classEnum : StatusCodeClass.values()) {
|
||||
if (classEnum.codeClass == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
StatusCodeClass(int codeClass) {
|
||||
this.codeClass = codeClass;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum StatusCodeDetail {
|
||||
UNDEFINED(StatusCodeSubject.UNDEFINED, 0),
|
||||
OTHER_ADDRESS_STATUS(StatusCodeSubject.ADDRESSING, 0),
|
||||
BAD_DESTINATION_MAILBOX_ADDRESS(StatusCodeSubject.ADDRESSING, 1),
|
||||
BAD_DESTINATION_SYSTEM_ADDRESS(StatusCodeSubject.ADDRESSING, 2),
|
||||
BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX(StatusCodeSubject.ADDRESSING, 3),
|
||||
DESTINATION_MAILBOX_ADDRESS_AMBIGUOUS(StatusCodeSubject.ADDRESSING, 4),
|
||||
DESTINATION_ADDRESS_VALID(StatusCodeSubject.ADDRESSING, 5),
|
||||
DESTINATION_MAILBOX_MOVED(StatusCodeSubject.ADDRESSING, 6),
|
||||
BAD_SENDER_MAILBOX_SYNTAX(StatusCodeSubject.ADDRESSING, 7),
|
||||
BAD_SENDER_SYSTEM_ADDRESS(StatusCodeSubject.ADDRESSING, 8),
|
||||
|
||||
OTHER_MAILBOX_STATUS(StatusCodeSubject.MAILBOX,0),
|
||||
MAILBOX_DISABLED(StatusCodeSubject.MAILBOX,1),
|
||||
MAILBOX_FULL(StatusCodeSubject.MAILBOX,2),
|
||||
MESSAGE_LENGTH_EXCEEDED(StatusCodeSubject.MAILBOX,3),
|
||||
MAILING_LIST_EXPANSION_PROBLEM(StatusCodeSubject.MAILBOX,4),
|
||||
|
||||
OTHER_MAIL_SYSTEM_STATUS(StatusCodeSubject.MAIL_SYSTEM,0),
|
||||
MAIL_SYSTEM_FULL(StatusCodeSubject.MAIL_SYSTEM,1),
|
||||
SYSTEM_NOT_ACCEPTING_MESSAGES(StatusCodeSubject.MAIL_SYSTEM,2),
|
||||
SYSTEM_INCAPABLE_OF_FEATURE(StatusCodeSubject.MAIL_SYSTEM,3),
|
||||
MESSAGE_TOO_BIG(StatusCodeSubject.MAIL_SYSTEM,4),
|
||||
SYSTEM_INCORRECTLY_CONFIGURED(StatusCodeSubject.MAIL_SYSTEM,5),
|
||||
|
||||
OTHER_NETWORK_ROUTING(StatusCodeSubject.NETWORK_ROUTING,0),
|
||||
NO_ANSWER_FROM_HOST(StatusCodeSubject.NETWORK_ROUTING,1),
|
||||
BAD_CONNECTION(StatusCodeSubject.NETWORK_ROUTING,2),
|
||||
DIRECTORY_SERVER_FAILURE(StatusCodeSubject.NETWORK_ROUTING,3),
|
||||
UNABLE_TO_ROUTE(StatusCodeSubject.NETWORK_ROUTING,4),
|
||||
MAIL_SYSTEM_CONGESTION(StatusCodeSubject.NETWORK_ROUTING,5),
|
||||
ROUTING_LOOP_DETECTED(StatusCodeSubject.NETWORK_ROUTING,6),
|
||||
DELIVERY_TIME_EXPIRED(StatusCodeSubject.NETWORK_ROUTING,7),
|
||||
|
||||
OTHER_MAIL_DELIVERY_PROTOCOL(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,0),
|
||||
INVALID_COMMAND(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,1),
|
||||
SYNTAX_ERROR(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,2),
|
||||
TOO_MANY_RECIPIENTS(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,3),
|
||||
INVALID_COMMAND_ARGUMENTS(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,4),
|
||||
WRONG_PROTOCOL_VERSION(StatusCodeSubject.MAIL_DELIVERY_PROTOCOL,5),
|
||||
|
||||
OTHER_MESSAGE_CONTENT_OR_MEDIA(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,0),
|
||||
MEDIA_NOT_SUPPORTED(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,1),
|
||||
CONVERSION_REQUIRED_AND_PROHIBITED(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,2),
|
||||
CONVERSION_REQUIRED_BUT_UNSUPPORTED(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,3),
|
||||
CONVERSION_WITH_LOSS_PERFORMED(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,4),
|
||||
CONVERSION_FAILED(StatusCodeSubject.MESSAGE_CONTENT_OR_MEDIA,5),
|
||||
|
||||
OTHER_SECURITY_OR_POLICY_STATUS(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 0),
|
||||
DELIVERY_NOT_AUTHORIZED(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 1),
|
||||
MAILING_LIST_EXPANSION_PROHIBITED(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 2),
|
||||
SECURITY_CONVERSION_REQUIRED(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 3),
|
||||
SECURITY_FEATURES_UNSUPPORTED(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 4),
|
||||
CRYPTOGRAPHIC_FAILURE(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 5),
|
||||
CRYPTOGRAPHIC_ALGORITHM_UNSUPPORTED(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 6),
|
||||
MESSAGE_INTEGRITY_FAILURE(StatusCodeSubject.SECURITY_OR_POLICY_STATUS, 7);
|
||||
|
||||
|
||||
private final StatusCodeSubject subject;
|
||||
private final int detail;
|
||||
|
||||
|
||||
public static StatusCodeDetail parse(StatusCodeSubject statusCodeSubject, String statusCodeDetailString) {
|
||||
int value = Integer.parseInt(statusCodeDetailString);
|
||||
for (StatusCodeDetail detailEnum : StatusCodeDetail.values()) {
|
||||
if (detailEnum.subject == statusCodeSubject && detailEnum.detail == value) {
|
||||
return detailEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
StatusCodeDetail(StatusCodeSubject subject, int detail) {
|
||||
this.subject = subject;
|
||||
this.detail = detail;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.fsck.k9.mail.transport.smtp;
|
||||
|
||||
|
||||
enum StatusCodeSubject {
|
||||
UNDEFINED(0),
|
||||
ADDRESSING(1),
|
||||
MAILBOX(2),
|
||||
MAIL_SYSTEM(3),
|
||||
NETWORK_ROUTING(4),
|
||||
MAIL_DELIVERY_PROTOCOL(5),
|
||||
MESSAGE_CONTENT_OR_MEDIA(6),
|
||||
SECURITY_OR_POLICY_STATUS(7);
|
||||
|
||||
|
||||
private final int codeSubject;
|
||||
|
||||
|
||||
static StatusCodeSubject parse(String statusCodeSubjectString) {
|
||||
int value = Integer.parseInt(statusCodeSubjectString);
|
||||
for (StatusCodeSubject classEnum : StatusCodeSubject.values()) {
|
||||
if (classEnum.codeSubject == value) {
|
||||
return classEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
StatusCodeSubject(int codeSubject) {
|
||||
this.codeSubject = codeSubject;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue