From 090301ae3d2ff1dae80f340367461a3551f21c3a Mon Sep 17 00:00:00 2001 From: "Hoa V. Dinh" Date: Mon, 5 Jan 2015 12:55:18 -0800 Subject: Implemented error message for Java --- build-mac/mailcore2.xcodeproj/project.pbxproj | 8 ++ src/cmake/core.cmake | 1 + src/core/abstract/MCErrorMessage.cpp | 58 ++++++++++++++ src/core/abstract/MCErrorMessage.h | 11 +++ src/java/com/libmailcore/Error.java | 46 ----------- src/java/com/libmailcore/ErrorCode.java | 46 +++++++++++ src/java/com/libmailcore/IMAPOperation.java | 4 +- src/java/com/libmailcore/MailException.java | 49 +----------- src/java/generate-headers.sh | 7 +- src/java/native/com_libmailcore_Error.h | 97 ----------------------- src/java/native/com_libmailcore_ErrorCode.h | 97 +++++++++++++++++++++++ src/java/native/com_libmailcore_MailException.cpp | 13 +++ src/java/native/com_libmailcore_MailException.h | 94 ++-------------------- src/objc/utils/MCOUtils.h | 1 - src/objc/utils/NSError+MCO.mm | 55 +++---------- 15 files changed, 261 insertions(+), 326 deletions(-) create mode 100644 src/core/abstract/MCErrorMessage.cpp create mode 100644 src/core/abstract/MCErrorMessage.h delete mode 100644 src/java/com/libmailcore/Error.java create mode 100644 src/java/com/libmailcore/ErrorCode.java delete mode 100644 src/java/native/com_libmailcore_Error.h create mode 100644 src/java/native/com_libmailcore_ErrorCode.h create mode 100644 src/java/native/com_libmailcore_MailException.cpp diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index eb47b08d..fcc4830b 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -166,6 +166,8 @@ BD6272981A13FF2A00129AA8 /* test-all-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BD6272961A13FF2A00129AA8 /* test-all-mac.mm */; }; BD6272991A13FF2A00129AA8 /* test-all-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BD6272961A13FF2A00129AA8 /* test-all-mac.mm */; }; BD63713B177DFF080094121B /* MCLibetpan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BD637139177DFF080094121B /* MCLibetpan.cpp */; }; + BDCD7C5B1A5B1C2C0001DCC3 /* MCErrorMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BDCD7C591A5B1C2C0001DCC3 /* MCErrorMessage.cpp */; }; + BDCD7C5C1A5B1C2C0001DCC3 /* MCErrorMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BDCD7C591A5B1C2C0001DCC3 /* MCErrorMessage.cpp */; }; C07AD5D7FD82F8ACAB576231 /* NSError+MCO.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C07AD44B013BB42A240B4F04 /* NSError+MCO.h */; }; C07AD99B2E2054C684DB8FF6 /* NSError+MCO.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07ADFE43E22B38EFF23ADB5 /* NSError+MCO.mm */; }; C07ADC28B83E7959BF114D46 /* MCOIMAPSession.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */; }; @@ -1489,6 +1491,8 @@ BD62729C1A158DA900129AA8 /* MCWin32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCWin32.h; sourceTree = ""; }; BD637139177DFF080094121B /* MCLibetpan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCLibetpan.cpp; sourceTree = ""; }; BD63713A177DFF080094121B /* MCLibetpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCLibetpan.h; sourceTree = ""; }; + BDCD7C591A5B1C2C0001DCC3 /* MCErrorMessage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCErrorMessage.cpp; sourceTree = ""; }; + BDCD7C5A1A5B1C2C0001DCC3 /* MCErrorMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCErrorMessage.h; sourceTree = ""; }; C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPSession.mm; sourceTree = ""; }; C07AD44B013BB42A240B4F04 /* NSError+MCO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+MCO.h"; sourceTree = ""; }; C07ADFE43E22B38EFF23ADB5 /* NSError+MCO.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSError+MCO.mm"; sourceTree = ""; }; @@ -2349,6 +2353,8 @@ C64EA692169E847800778456 /* abstract */ = { isa = PBXGroup; children = ( + BDCD7C591A5B1C2C0001DCC3 /* MCErrorMessage.cpp */, + BDCD7C5A1A5B1C2C0001DCC3 /* MCErrorMessage.h */, C64EA693169E847800778456 /* MCAbstract.h */, C64EA694169E847800778456 /* MCAbstractMessage.cpp */, C64EA695169E847800778456 /* MCAbstractMessage.h */, @@ -3321,6 +3327,7 @@ C6D6F954171E5CB8006F5B28 /* MCMD5.cpp in Sources */, C6D6F956171E5CB8006F5B28 /* MCNull.cpp in Sources */, C6D6F967171FCF9F006F5B28 /* MCJSONParser.cpp in Sources */, + BDCD7C5B1A5B1C2C0001DCC3 /* MCErrorMessage.cpp in Sources */, 84CFA98719F7159700FE35D2 /* MCNNTPFetchOverviewOperation.cpp in Sources */, 84D73768199BFFFC005124E5 /* MCONNTPOperation.mm in Sources */, C668E2C71735C8D500A2BB47 /* MCObjectMac.mm in Sources */, @@ -3566,6 +3573,7 @@ C6D6F7FA171E595D006F5B28 /* MCJSON.cpp in Sources */, C6D6F955171E5CB8006F5B28 /* MCMD5.cpp in Sources */, C6D6F957171E5CB8006F5B28 /* MCNull.cpp in Sources */, + BDCD7C5C1A5B1C2C0001DCC3 /* MCErrorMessage.cpp in Sources */, 84CFA98819F7159700FE35D2 /* MCNNTPFetchOverviewOperation.cpp in Sources */, C6D6F968171FCF9F006F5B28 /* MCJSONParser.cpp in Sources */, 84D73769199BFFFC005124E5 /* MCONNTPOperation.mm in Sources */, diff --git a/src/cmake/core.cmake b/src/cmake/core.cmake index e8aa0185..51ce8929 100644 --- a/src/cmake/core.cmake +++ b/src/cmake/core.cmake @@ -7,6 +7,7 @@ set(abstract_files core/abstract/MCAbstractPart.cpp core/abstract/MCAddress.cpp core/abstract/MCMessageHeader.cpp + core/abstract/MCErrorMessage.cpp ) IF(APPLE) diff --git a/src/core/abstract/MCErrorMessage.cpp b/src/core/abstract/MCErrorMessage.cpp new file mode 100644 index 00000000..c7205d42 --- /dev/null +++ b/src/core/abstract/MCErrorMessage.cpp @@ -0,0 +1,58 @@ +#include "MCErrorMessage.h" + +using namespace mailcore; + +static const char * localizedDescriptionTable[] = { + "The operation succeeded.", /** MCOErrorNone */ + "A stable connection to the server could not be established.", /** MCOErrorConnection */ + "The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ + "Unable to parse response from server.", /** MCOErrorParse */ + "The certificate for this server is invalid.", /** MCOErrorCertificate */ + "Unable to authenticate with the current session's credentials.", /** MCOErrorAuthentication */ + "IMAP is not enabled for this Gmail account.", /** MCOErrorGmailIMAPNotEnabled */ + "Bandwidth limits were exceeded while requesting data from this Gmail account.", /** MCOErrorGmailExceededBandwidthLimit */ + "Too many simultaneous connections were made to this Gmail account.", /** MCOErrorGmailTooManySimultaneousConnections */ + "MobileMe is no longer an active mail service.", /** MCOErrorMobileMeMoved */ + "Yahoo!'s servers are currently unavailable.", /** MCOErrorYahooUnavailable */ + "The requested folder does not exist. Folder selection failed", /** MCOErrorNonExistantFolder */ + "An error occured while renaming the requested folder.", /** MCOErrorRename */ + "An error occured while deleting the requested folder.", /** MCOErrorDelete */ + "An error occured while creating the requested folder.", /** MCOErrorCreate */ + "An error occured while (un)subscribing to the requested folder.", /** MCOErrorSubscribe */ + "An error occured while appending a message to the requested folder.", /** MCOErrorAppend */ + "An error occured while copying a message to the requested folder.", /** MCOErrorCopy */ + "An error occured while expunging a message in the requested folder.", /** MCOErrorExpunge */ + "An error occured while fetching messages in the requested folder.", /** MCOErrorFetch */ + "An error occured during an IDLE operation.", /** MCOErrorIdle */ + "An error occured while requesting the server's identity.", /** MCOErrorIdentity */ + "An error occured while requesting the server's namespace.", /** MCOErrorNamespace */ + "An error occured while storing flags.", /** MCOErrorStore */ + "An error occured while requesting the server's capabilities.", /** MCOErrorCapability */ + "The server does not support STARTTLS connections.", /** MCOErrorStartTLSNotAvailable */ + "Attempted to send a message with an illegal attachment.", /** MCOErrorSendMessageIllegalAttachment */ + "The SMTP storage limit was hit while trying to send a large message.", /** MCOErrorStorageLimit */ + "Sending messages is not allowed on this server.", /** MCOErrorSendMessageNotAllowed */ + "The current HotMail account cannot connect to WebMail.", /** MCOErrorNeedsConnectToWebmail */ + "An error occured while sending the message.", /** MCOErrorSendMessage */ + "Authentication is required for this SMTP server.", /** MCOErrorAuthenticationRequired */ + "An error occured while fetching a message list on the POP server.", /** MCOErrorFetchMessageList */ + "An error occured while deleting a message on the POP server.", /** MCOErrorDeleteMessage */ + "Account check failed because the account is invalid.", /** MCOErrorInvalidAccount */ + "File access error", /** MCOErrorFile */ + "Compression is not available", /** MCOErrorCompression */ + "A sender is required to send message", /** MCOErrorNoSender */ + "A recipient is required to send message", /** MCOErrorNoRecipient */ + "An error occured while performing a No-Op operation.", /** MCOErrorNoop */ + "An application specific password is required", /** MCOErrorGmailApplicationSpecificPasswordRequired */ +}; + +String * mailcore::errorMessageWithErrorCode(ErrorCode errorCode) +{ + if (errorCode < 0) { + return NULL; + } + if (errorCode >= sizeof(localizedDescriptionTable) / sizeof(localizedDescriptionTable[0])) { + return NULL; + } + return String::stringWithUTF8Characters(localizedDescriptionTable[errorCode]); +} diff --git a/src/core/abstract/MCErrorMessage.h b/src/core/abstract/MCErrorMessage.h new file mode 100644 index 00000000..12abd97b --- /dev/null +++ b/src/core/abstract/MCErrorMessage.h @@ -0,0 +1,11 @@ +#ifndef MAILCORE_MCERRORMESSAGE_H + +#define MAILCORE_MCERRORMESSAGE_H + +#include + +namespace mailcore { +String * errorMessageWithErrorCode(ErrorCode errorCode); +} + +#endif diff --git a/src/java/com/libmailcore/Error.java b/src/java/com/libmailcore/Error.java deleted file mode 100644 index b0c4fc40..00000000 --- a/src/java/com/libmailcore/Error.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.libmailcore; - -public class Error { - public final static int ErrorNone = 0; // 0 - public final static int ErrorConnection = 1; - public final static int ErrorTLSNotAvailable = 2; - public final static int ErrorParse = 3; - public final static int ErrorCertificate = 4; - public final static int ErrorAuthentication = 5; - public final static int ErrorGmailIMAPNotEnabled = 6; - public final static int ErrorGmailExceededBandwidthLimit = 7; - public final static int ErrorGmailTooManySimultaneousConnections = 8; - public final static int ErrorMobileMeMoved = 9; - public final static int ErrorYahooUnavailable = 10; // 10 - public final static int ErrorNonExistantFolder = 11; - public final static int ErrorRename = 12; - public final static int ErrorDelete = 13; - public final static int ErrorCreate = 14; - public final static int ErrorSubscribe = 15; - public final static int ErrorAppend = 16; - public final static int ErrorCopy = 17; - public final static int ErrorExpunge = 18; - public final static int ErrorFetch = 19; - public final static int ErrorIdle = 20; // 20 - public final static int ErrorIdentity = 21; - public final static int ErrorNamespace = 22; - public final static int ErrorStore = 23; - public final static int ErrorCapability = 24; - public final static int ErrorStartTLSNotAvailable = 25; - public final static int ErrorSendMessageIllegalAttachment = 26; - public final static int ErrorStorageLimit = 27; - public final static int ErrorSendMessageNotAllowed = 28; - public final static int ErrorNeedsConnectToWebmail = 29; - public final static int ErrorSendMessage = 30; // 30 - public final static int ErrorAuthenticationRequired = 31; - public final static int ErrorFetchMessageList = 32; - public final static int ErrorDeleteMessage = 33; - public final static int ErrorInvalidAccount = 34; - public final static int ErrorFile = 35; - public final static int ErrorCompression = 36; - public final static int ErrorNoSender = 37; - public final static int ErrorNoRecipient = 38; - public final static int ErrorNoop = 39; - public final static int ErrorGmailApplicationSpecificPasswordRequired = 40; // 40 - public final static int ErrorServerDate = 41; -} diff --git a/src/java/com/libmailcore/ErrorCode.java b/src/java/com/libmailcore/ErrorCode.java new file mode 100644 index 00000000..85686411 --- /dev/null +++ b/src/java/com/libmailcore/ErrorCode.java @@ -0,0 +1,46 @@ +package com.libmailcore; + +public class ErrorCode { + public final static int ErrorNone = 0; // 0 + public final static int ErrorConnection = 1; + public final static int ErrorTLSNotAvailable = 2; + public final static int ErrorParse = 3; + public final static int ErrorCertificate = 4; + public final static int ErrorAuthentication = 5; + public final static int ErrorGmailIMAPNotEnabled = 6; + public final static int ErrorGmailExceededBandwidthLimit = 7; + public final static int ErrorGmailTooManySimultaneousConnections = 8; + public final static int ErrorMobileMeMoved = 9; + public final static int ErrorYahooUnavailable = 10; // 10 + public final static int ErrorNonExistantFolder = 11; + public final static int ErrorRename = 12; + public final static int ErrorDelete = 13; + public final static int ErrorCreate = 14; + public final static int ErrorSubscribe = 15; + public final static int ErrorAppend = 16; + public final static int ErrorCopy = 17; + public final static int ErrorExpunge = 18; + public final static int ErrorFetch = 19; + public final static int ErrorIdle = 20; // 20 + public final static int ErrorIdentity = 21; + public final static int ErrorNamespace = 22; + public final static int ErrorStore = 23; + public final static int ErrorCapability = 24; + public final static int ErrorStartTLSNotAvailable = 25; + public final static int ErrorSendMessageIllegalAttachment = 26; + public final static int ErrorStorageLimit = 27; + public final static int ErrorSendMessageNotAllowed = 28; + public final static int ErrorNeedsConnectToWebmail = 29; + public final static int ErrorSendMessage = 30; // 30 + public final static int ErrorAuthenticationRequired = 31; + public final static int ErrorFetchMessageList = 32; + public final static int ErrorDeleteMessage = 33; + public final static int ErrorInvalidAccount = 34; + public final static int ErrorFile = 35; + public final static int ErrorCompression = 36; + public final static int ErrorNoSender = 37; + public final static int ErrorNoRecipient = 38; + public final static int ErrorNoop = 39; + public final static int ErrorGmailApplicationSpecificPasswordRequired = 40; // 40 + public final static int ErrorServerDate = 41; +} diff --git a/src/java/com/libmailcore/IMAPOperation.java b/src/java/com/libmailcore/IMAPOperation.java index 5790ec29..4fea241f 100644 --- a/src/java/com/libmailcore/IMAPOperation.java +++ b/src/java/com/libmailcore/IMAPOperation.java @@ -2,7 +2,7 @@ package com.libmailcore; public class IMAPOperation extends Operation { public MailException exception() { - if (errorCode() == Error.ErrorNone) { + if (errorCode() == ErrorCode.ErrorNone) { return null; } return new MailException(errorCode()); @@ -13,7 +13,7 @@ public class IMAPOperation extends Operation { protected void callCallback() { if (callback != null) { - if (errorCode() == Error.ErrorNone) { + if (errorCode() == ErrorCode.ErrorNone) { callback.succeeded(); } else { diff --git a/src/java/com/libmailcore/MailException.java b/src/java/com/libmailcore/MailException.java index 9c152d70..a101b3e3 100644 --- a/src/java/com/libmailcore/MailException.java +++ b/src/java/com/libmailcore/MailException.java @@ -18,54 +18,7 @@ public class MailException extends Exception { errorCode = anErrorCode; } - private static String messageForErrorCode(int errorCode) - { - return "Error"; - } - - static final int ERROR_NONE = 0; - static final int ERROR_CONNECTION = 1; - static final int ERROR_TLS_NOT_AVAILABLE = 2; - static final int ERROR_PARSE = 3; - static final int ERROR_CERTIFICATE = 4; - static final int ERROR_AUTHENTICATION = 5; - static final int ERROR_GMAIL_IMAP_NOT_ENABLED = 6; - static final int ERROR_GMAIL_EXCEED_BANDWIDTH_LIMIT = 7; - static final int ERROR_GMAIL_TOO_MANY_SIMULTANEOUS_CONNECTIONS = 8; - static final int ERROR_MOBILEME_MOVED = 9; - static final int ERROR_YAHOO_UNAVAILABLE = 10; - static final int ERROR_NON_EXISTANT_FOLDER = 11; - static final int ERROR_RENAME = 12; - static final int ERROR_DELETE = 13; - static final int ERROR_CREATE = 14; - static final int ERROR_SUBSCRIBED = 15; - static final int ERROR_APPEND = 16; - static final int ERROR_COPY = 17; - static final int ERROR_EXPUNGE = 18; - static final int ERROR_FETCH = 19; - static final int ERROR_IDLE = 20; - static final int ERROR_IDENTITY = 21; - static final int ERROR_NAMESPACE = 22; - static final int ERROR_STORE = 23; - static final int ERROR_CAPABILITY = 24; - static final int ERROR_STARTTLS_NOT_AVAILABLE = 25; - static final int ERROR_SEND_MESSAGE_ILLEGAL_ATTACHMENT = 26; - static final int ERROR_STORAGE_LIMIT = 27; - static final int ERROR_SEND_MESSAGE_NOT_ALLOWED = 28; - static final int ERROR_NEEDS_CONNECT_TO_WEBMAIL = 29; - static final int ERROR_SEND_MESSAGE = 30; - static final int ERROR_AUTHENTICATION_REQUIRED = 31; - static final int ERROR_FETCH_MESSAGE_LIST = 32; - static final int ERROR_DELETE_MESSAGE = 33; - static final int ERROR_INVALID_ACCOUNT = 34; - static final int ERROR_FILE = 35; - static final int ERROR_COMPRESSION = 36; - static final int ERROR_NO_SENDER = 37; - static final int ERROR_NO_RECIPIENT = 38; - static final int ERROR_NOOP = 39; - static final int ERROR_GMAIL_APPLICATION_SPECIFIC_PASSWORD_REQUIRED = 40; - static final int ERROR_SERVER_DATE = 41; - static final int ERROR_COUNT = 42; + private static native String messageForErrorCode(int errorCode); private int errorCode; } \ No newline at end of file diff --git a/src/java/generate-headers.sh b/src/java/generate-headers.sh index ed273439..2e75de5a 100755 --- a/src/java/generate-headers.sh +++ b/src/java/generate-headers.sh @@ -1,5 +1,10 @@ #!/bin/bash -ANDROID_SDK=$HOME/Android/android-sdk-macosx + +if test "x$ANDROID_SDK" = x ; then + echo should set ANDROID_SDK before running this script. + exit 1 +fi + TARGET_PLATFORM=android-21 echo Building Java diff --git a/src/java/native/com_libmailcore_Error.h b/src/java/native/com_libmailcore_Error.h deleted file mode 100644 index 345b3eef..00000000 --- a/src/java/native/com_libmailcore_Error.h +++ /dev/null @@ -1,97 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_libmailcore_Error */ - -#ifndef _Included_com_libmailcore_Error -#define _Included_com_libmailcore_Error -#ifdef __cplusplus -extern "C" { -#endif -#undef com_libmailcore_Error_ErrorNone -#define com_libmailcore_Error_ErrorNone 0L -#undef com_libmailcore_Error_ErrorConnection -#define com_libmailcore_Error_ErrorConnection 1L -#undef com_libmailcore_Error_ErrorTLSNotAvailable -#define com_libmailcore_Error_ErrorTLSNotAvailable 2L -#undef com_libmailcore_Error_ErrorParse -#define com_libmailcore_Error_ErrorParse 3L -#undef com_libmailcore_Error_ErrorCertificate -#define com_libmailcore_Error_ErrorCertificate 4L -#undef com_libmailcore_Error_ErrorAuthentication -#define com_libmailcore_Error_ErrorAuthentication 5L -#undef com_libmailcore_Error_ErrorGmailIMAPNotEnabled -#define com_libmailcore_Error_ErrorGmailIMAPNotEnabled 6L -#undef com_libmailcore_Error_ErrorGmailExceededBandwidthLimit -#define com_libmailcore_Error_ErrorGmailExceededBandwidthLimit 7L -#undef com_libmailcore_Error_ErrorGmailTooManySimultaneousConnections -#define com_libmailcore_Error_ErrorGmailTooManySimultaneousConnections 8L -#undef com_libmailcore_Error_ErrorMobileMeMoved -#define com_libmailcore_Error_ErrorMobileMeMoved 9L -#undef com_libmailcore_Error_ErrorYahooUnavailable -#define com_libmailcore_Error_ErrorYahooUnavailable 10L -#undef com_libmailcore_Error_ErrorNonExistantFolder -#define com_libmailcore_Error_ErrorNonExistantFolder 11L -#undef com_libmailcore_Error_ErrorRename -#define com_libmailcore_Error_ErrorRename 12L -#undef com_libmailcore_Error_ErrorDelete -#define com_libmailcore_Error_ErrorDelete 13L -#undef com_libmailcore_Error_ErrorCreate -#define com_libmailcore_Error_ErrorCreate 14L -#undef com_libmailcore_Error_ErrorSubscribe -#define com_libmailcore_Error_ErrorSubscribe 15L -#undef com_libmailcore_Error_ErrorAppend -#define com_libmailcore_Error_ErrorAppend 16L -#undef com_libmailcore_Error_ErrorCopy -#define com_libmailcore_Error_ErrorCopy 17L -#undef com_libmailcore_Error_ErrorExpunge -#define com_libmailcore_Error_ErrorExpunge 18L -#undef com_libmailcore_Error_ErrorFetch -#define com_libmailcore_Error_ErrorFetch 19L -#undef com_libmailcore_Error_ErrorIdle -#define com_libmailcore_Error_ErrorIdle 20L -#undef com_libmailcore_Error_ErrorIdentity -#define com_libmailcore_Error_ErrorIdentity 21L -#undef com_libmailcore_Error_ErrorNamespace -#define com_libmailcore_Error_ErrorNamespace 22L -#undef com_libmailcore_Error_ErrorStore -#define com_libmailcore_Error_ErrorStore 23L -#undef com_libmailcore_Error_ErrorCapability -#define com_libmailcore_Error_ErrorCapability 24L -#undef com_libmailcore_Error_ErrorStartTLSNotAvailable -#define com_libmailcore_Error_ErrorStartTLSNotAvailable 25L -#undef com_libmailcore_Error_ErrorSendMessageIllegalAttachment -#define com_libmailcore_Error_ErrorSendMessageIllegalAttachment 26L -#undef com_libmailcore_Error_ErrorStorageLimit -#define com_libmailcore_Error_ErrorStorageLimit 27L -#undef com_libmailcore_Error_ErrorSendMessageNotAllowed -#define com_libmailcore_Error_ErrorSendMessageNotAllowed 28L -#undef com_libmailcore_Error_ErrorNeedsConnectToWebmail -#define com_libmailcore_Error_ErrorNeedsConnectToWebmail 29L -#undef com_libmailcore_Error_ErrorSendMessage -#define com_libmailcore_Error_ErrorSendMessage 30L -#undef com_libmailcore_Error_ErrorAuthenticationRequired -#define com_libmailcore_Error_ErrorAuthenticationRequired 31L -#undef com_libmailcore_Error_ErrorFetchMessageList -#define com_libmailcore_Error_ErrorFetchMessageList 32L -#undef com_libmailcore_Error_ErrorDeleteMessage -#define com_libmailcore_Error_ErrorDeleteMessage 33L -#undef com_libmailcore_Error_ErrorInvalidAccount -#define com_libmailcore_Error_ErrorInvalidAccount 34L -#undef com_libmailcore_Error_ErrorFile -#define com_libmailcore_Error_ErrorFile 35L -#undef com_libmailcore_Error_ErrorCompression -#define com_libmailcore_Error_ErrorCompression 36L -#undef com_libmailcore_Error_ErrorNoSender -#define com_libmailcore_Error_ErrorNoSender 37L -#undef com_libmailcore_Error_ErrorNoRecipient -#define com_libmailcore_Error_ErrorNoRecipient 38L -#undef com_libmailcore_Error_ErrorNoop -#define com_libmailcore_Error_ErrorNoop 39L -#undef com_libmailcore_Error_ErrorGmailApplicationSpecificPasswordRequired -#define com_libmailcore_Error_ErrorGmailApplicationSpecificPasswordRequired 40L -#undef com_libmailcore_Error_ErrorServerDate -#define com_libmailcore_Error_ErrorServerDate 41L -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/java/native/com_libmailcore_ErrorCode.h b/src/java/native/com_libmailcore_ErrorCode.h new file mode 100644 index 00000000..214bd6d7 --- /dev/null +++ b/src/java/native/com_libmailcore_ErrorCode.h @@ -0,0 +1,97 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_libmailcore_ErrorCode */ + +#ifndef _Included_com_libmailcore_ErrorCode +#define _Included_com_libmailcore_ErrorCode +#ifdef __cplusplus +extern "C" { +#endif +#undef com_libmailcore_ErrorCode_ErrorNone +#define com_libmailcore_ErrorCode_ErrorNone 0L +#undef com_libmailcore_ErrorCode_ErrorConnection +#define com_libmailcore_ErrorCode_ErrorConnection 1L +#undef com_libmailcore_ErrorCode_ErrorTLSNotAvailable +#define com_libmailcore_ErrorCode_ErrorTLSNotAvailable 2L +#undef com_libmailcore_ErrorCode_ErrorParse +#define com_libmailcore_ErrorCode_ErrorParse 3L +#undef com_libmailcore_ErrorCode_ErrorCertificate +#define com_libmailcore_ErrorCode_ErrorCertificate 4L +#undef com_libmailcore_ErrorCode_ErrorAuthentication +#define com_libmailcore_ErrorCode_ErrorAuthentication 5L +#undef com_libmailcore_ErrorCode_ErrorGmailIMAPNotEnabled +#define com_libmailcore_ErrorCode_ErrorGmailIMAPNotEnabled 6L +#undef com_libmailcore_ErrorCode_ErrorGmailExceededBandwidthLimit +#define com_libmailcore_ErrorCode_ErrorGmailExceededBandwidthLimit 7L +#undef com_libmailcore_ErrorCode_ErrorGmailTooManySimultaneousConnections +#define com_libmailcore_ErrorCode_ErrorGmailTooManySimultaneousConnections 8L +#undef com_libmailcore_ErrorCode_ErrorMobileMeMoved +#define com_libmailcore_ErrorCode_ErrorMobileMeMoved 9L +#undef com_libmailcore_ErrorCode_ErrorYahooUnavailable +#define com_libmailcore_ErrorCode_ErrorYahooUnavailable 10L +#undef com_libmailcore_ErrorCode_ErrorNonExistantFolder +#define com_libmailcore_ErrorCode_ErrorNonExistantFolder 11L +#undef com_libmailcore_ErrorCode_ErrorRename +#define com_libmailcore_ErrorCode_ErrorRename 12L +#undef com_libmailcore_ErrorCode_ErrorDelete +#define com_libmailcore_ErrorCode_ErrorDelete 13L +#undef com_libmailcore_ErrorCode_ErrorCreate +#define com_libmailcore_ErrorCode_ErrorCreate 14L +#undef com_libmailcore_ErrorCode_ErrorSubscribe +#define com_libmailcore_ErrorCode_ErrorSubscribe 15L +#undef com_libmailcore_ErrorCode_ErrorAppend +#define com_libmailcore_ErrorCode_ErrorAppend 16L +#undef com_libmailcore_ErrorCode_ErrorCopy +#define com_libmailcore_ErrorCode_ErrorCopy 17L +#undef com_libmailcore_ErrorCode_ErrorExpunge +#define com_libmailcore_ErrorCode_ErrorExpunge 18L +#undef com_libmailcore_ErrorCode_ErrorFetch +#define com_libmailcore_ErrorCode_ErrorFetch 19L +#undef com_libmailcore_ErrorCode_ErrorIdle +#define com_libmailcore_ErrorCode_ErrorIdle 20L +#undef com_libmailcore_ErrorCode_ErrorIdentity +#define com_libmailcore_ErrorCode_ErrorIdentity 21L +#undef com_libmailcore_ErrorCode_ErrorNamespace +#define com_libmailcore_ErrorCode_ErrorNamespace 22L +#undef com_libmailcore_ErrorCode_ErrorStore +#define com_libmailcore_ErrorCode_ErrorStore 23L +#undef com_libmailcore_ErrorCode_ErrorCapability +#define com_libmailcore_ErrorCode_ErrorCapability 24L +#undef com_libmailcore_ErrorCode_ErrorStartTLSNotAvailable +#define com_libmailcore_ErrorCode_ErrorStartTLSNotAvailable 25L +#undef com_libmailcore_ErrorCode_ErrorSendMessageIllegalAttachment +#define com_libmailcore_ErrorCode_ErrorSendMessageIllegalAttachment 26L +#undef com_libmailcore_ErrorCode_ErrorStorageLimit +#define com_libmailcore_ErrorCode_ErrorStorageLimit 27L +#undef com_libmailcore_ErrorCode_ErrorSendMessageNotAllowed +#define com_libmailcore_ErrorCode_ErrorSendMessageNotAllowed 28L +#undef com_libmailcore_ErrorCode_ErrorNeedsConnectToWebmail +#define com_libmailcore_ErrorCode_ErrorNeedsConnectToWebmail 29L +#undef com_libmailcore_ErrorCode_ErrorSendMessage +#define com_libmailcore_ErrorCode_ErrorSendMessage 30L +#undef com_libmailcore_ErrorCode_ErrorAuthenticationRequired +#define com_libmailcore_ErrorCode_ErrorAuthenticationRequired 31L +#undef com_libmailcore_ErrorCode_ErrorFetchMessageList +#define com_libmailcore_ErrorCode_ErrorFetchMessageList 32L +#undef com_libmailcore_ErrorCode_ErrorDeleteMessage +#define com_libmailcore_ErrorCode_ErrorDeleteMessage 33L +#undef com_libmailcore_ErrorCode_ErrorInvalidAccount +#define com_libmailcore_ErrorCode_ErrorInvalidAccount 34L +#undef com_libmailcore_ErrorCode_ErrorFile +#define com_libmailcore_ErrorCode_ErrorFile 35L +#undef com_libmailcore_ErrorCode_ErrorCompression +#define com_libmailcore_ErrorCode_ErrorCompression 36L +#undef com_libmailcore_ErrorCode_ErrorNoSender +#define com_libmailcore_ErrorCode_ErrorNoSender 37L +#undef com_libmailcore_ErrorCode_ErrorNoRecipient +#define com_libmailcore_ErrorCode_ErrorNoRecipient 38L +#undef com_libmailcore_ErrorCode_ErrorNoop +#define com_libmailcore_ErrorCode_ErrorNoop 39L +#undef com_libmailcore_ErrorCode_ErrorGmailApplicationSpecificPasswordRequired +#define com_libmailcore_ErrorCode_ErrorGmailApplicationSpecificPasswordRequired 40L +#undef com_libmailcore_ErrorCode_ErrorServerDate +#define com_libmailcore_ErrorCode_ErrorServerDate 41L +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/java/native/com_libmailcore_MailException.cpp b/src/java/native/com_libmailcore_MailException.cpp new file mode 100644 index 00000000..79d5ba17 --- /dev/null +++ b/src/java/native/com_libmailcore_MailException.cpp @@ -0,0 +1,13 @@ +#include "com_libmailcore_MailException.h" + +#include "MCBaseTypes.h" +#include "MCErrorMessage.h" +#include "TypesUtils.h" + +using namespace mailcore; + +JNIEXPORT jstring JNICALL Java_com_libmailcore_MailException_messageForErrorCode + (JNIEnv * env, jclass cls, jint errorCode) +{ + return (jstring) MC_TO_JAVA(mailcore::errorMessageWithErrorCode((ErrorCode) errorCode)); +} diff --git a/src/java/native/com_libmailcore_MailException.h b/src/java/native/com_libmailcore_MailException.h index 6215d31e..1af6f002 100644 --- a/src/java/native/com_libmailcore_MailException.h +++ b/src/java/native/com_libmailcore_MailException.h @@ -11,92 +11,14 @@ extern "C" { #define com_libmailcore_MailException_serialVersionUID -3042686055658047285LL #undef com_libmailcore_MailException_serialVersionUID #define com_libmailcore_MailException_serialVersionUID -3387516993124229948LL -#undef com_libmailcore_MailException_ERROR_NONE -#define com_libmailcore_MailException_ERROR_NONE 0L -#undef com_libmailcore_MailException_ERROR_CONNECTION -#define com_libmailcore_MailException_ERROR_CONNECTION 1L -#undef com_libmailcore_MailException_ERROR_TLS_NOT_AVAILABLE -#define com_libmailcore_MailException_ERROR_TLS_NOT_AVAILABLE 2L -#undef com_libmailcore_MailException_ERROR_PARSE -#define com_libmailcore_MailException_ERROR_PARSE 3L -#undef com_libmailcore_MailException_ERROR_CERTIFICATE -#define com_libmailcore_MailException_ERROR_CERTIFICATE 4L -#undef com_libmailcore_MailException_ERROR_AUTHENTICATION -#define com_libmailcore_MailException_ERROR_AUTHENTICATION 5L -#undef com_libmailcore_MailException_ERROR_GMAIL_IMAP_NOT_ENABLED -#define com_libmailcore_MailException_ERROR_GMAIL_IMAP_NOT_ENABLED 6L -#undef com_libmailcore_MailException_ERROR_GMAIL_EXCEED_BANDWIDTH_LIMIT -#define com_libmailcore_MailException_ERROR_GMAIL_EXCEED_BANDWIDTH_LIMIT 7L -#undef com_libmailcore_MailException_ERROR_GMAIL_TOO_MANY_SIMULTANEOUS_CONNECTIONS -#define com_libmailcore_MailException_ERROR_GMAIL_TOO_MANY_SIMULTANEOUS_CONNECTIONS 8L -#undef com_libmailcore_MailException_ERROR_MOBILEME_MOVED -#define com_libmailcore_MailException_ERROR_MOBILEME_MOVED 9L -#undef com_libmailcore_MailException_ERROR_YAHOO_UNAVAILABLE -#define com_libmailcore_MailException_ERROR_YAHOO_UNAVAILABLE 10L -#undef com_libmailcore_MailException_ERROR_NON_EXISTANT_FOLDER -#define com_libmailcore_MailException_ERROR_NON_EXISTANT_FOLDER 11L -#undef com_libmailcore_MailException_ERROR_RENAME -#define com_libmailcore_MailException_ERROR_RENAME 12L -#undef com_libmailcore_MailException_ERROR_DELETE -#define com_libmailcore_MailException_ERROR_DELETE 13L -#undef com_libmailcore_MailException_ERROR_CREATE -#define com_libmailcore_MailException_ERROR_CREATE 14L -#undef com_libmailcore_MailException_ERROR_SUBSCRIBED -#define com_libmailcore_MailException_ERROR_SUBSCRIBED 15L -#undef com_libmailcore_MailException_ERROR_APPEND -#define com_libmailcore_MailException_ERROR_APPEND 16L -#undef com_libmailcore_MailException_ERROR_COPY -#define com_libmailcore_MailException_ERROR_COPY 17L -#undef com_libmailcore_MailException_ERROR_EXPUNGE -#define com_libmailcore_MailException_ERROR_EXPUNGE 18L -#undef com_libmailcore_MailException_ERROR_FETCH -#define com_libmailcore_MailException_ERROR_FETCH 19L -#undef com_libmailcore_MailException_ERROR_IDLE -#define com_libmailcore_MailException_ERROR_IDLE 20L -#undef com_libmailcore_MailException_ERROR_IDENTITY -#define com_libmailcore_MailException_ERROR_IDENTITY 21L -#undef com_libmailcore_MailException_ERROR_NAMESPACE -#define com_libmailcore_MailException_ERROR_NAMESPACE 22L -#undef com_libmailcore_MailException_ERROR_STORE -#define com_libmailcore_MailException_ERROR_STORE 23L -#undef com_libmailcore_MailException_ERROR_CAPABILITY -#define com_libmailcore_MailException_ERROR_CAPABILITY 24L -#undef com_libmailcore_MailException_ERROR_STARTTLS_NOT_AVAILABLE -#define com_libmailcore_MailException_ERROR_STARTTLS_NOT_AVAILABLE 25L -#undef com_libmailcore_MailException_ERROR_SEND_MESSAGE_ILLEGAL_ATTACHMENT -#define com_libmailcore_MailException_ERROR_SEND_MESSAGE_ILLEGAL_ATTACHMENT 26L -#undef com_libmailcore_MailException_ERROR_STORAGE_LIMIT -#define com_libmailcore_MailException_ERROR_STORAGE_LIMIT 27L -#undef com_libmailcore_MailException_ERROR_SEND_MESSAGE_NOT_ALLOWED -#define com_libmailcore_MailException_ERROR_SEND_MESSAGE_NOT_ALLOWED 28L -#undef com_libmailcore_MailException_ERROR_NEEDS_CONNECT_TO_WEBMAIL -#define com_libmailcore_MailException_ERROR_NEEDS_CONNECT_TO_WEBMAIL 29L -#undef com_libmailcore_MailException_ERROR_SEND_MESSAGE -#define com_libmailcore_MailException_ERROR_SEND_MESSAGE 30L -#undef com_libmailcore_MailException_ERROR_AUTHENTICATION_REQUIRED -#define com_libmailcore_MailException_ERROR_AUTHENTICATION_REQUIRED 31L -#undef com_libmailcore_MailException_ERROR_FETCH_MESSAGE_LIST -#define com_libmailcore_MailException_ERROR_FETCH_MESSAGE_LIST 32L -#undef com_libmailcore_MailException_ERROR_DELETE_MESSAGE -#define com_libmailcore_MailException_ERROR_DELETE_MESSAGE 33L -#undef com_libmailcore_MailException_ERROR_INVALID_ACCOUNT -#define com_libmailcore_MailException_ERROR_INVALID_ACCOUNT 34L -#undef com_libmailcore_MailException_ERROR_FILE -#define com_libmailcore_MailException_ERROR_FILE 35L -#undef com_libmailcore_MailException_ERROR_COMPRESSION -#define com_libmailcore_MailException_ERROR_COMPRESSION 36L -#undef com_libmailcore_MailException_ERROR_NO_SENDER -#define com_libmailcore_MailException_ERROR_NO_SENDER 37L -#undef com_libmailcore_MailException_ERROR_NO_RECIPIENT -#define com_libmailcore_MailException_ERROR_NO_RECIPIENT 38L -#undef com_libmailcore_MailException_ERROR_NOOP -#define com_libmailcore_MailException_ERROR_NOOP 39L -#undef com_libmailcore_MailException_ERROR_GMAIL_APPLICATION_SPECIFIC_PASSWORD_REQUIRED -#define com_libmailcore_MailException_ERROR_GMAIL_APPLICATION_SPECIFIC_PASSWORD_REQUIRED 40L -#undef com_libmailcore_MailException_ERROR_SERVER_DATE -#define com_libmailcore_MailException_ERROR_SERVER_DATE 41L -#undef com_libmailcore_MailException_ERROR_COUNT -#define com_libmailcore_MailException_ERROR_COUNT 42L +/* + * Class: com_libmailcore_MailException + * Method: messageForErrorCode + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_libmailcore_MailException_messageForErrorCode + (JNIEnv *, jclass, jint); + #ifdef __cplusplus } #endif diff --git a/src/objc/utils/MCOUtils.h b/src/objc/utils/MCOUtils.h index 30e83a7c..3c36a6ab 100644 --- a/src/objc/utils/MCOUtils.h +++ b/src/objc/utils/MCOUtils.h @@ -16,7 +16,6 @@ #import #import #import -#import #import #import #import diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm index b6b73f6d..56d571e4 100644 --- a/src/objc/utils/NSError+MCO.mm +++ b/src/objc/utils/NSError+MCO.mm @@ -5,51 +5,13 @@ #import "NSError+MCO.h" +#include "MCBaseTypes.h" +#include "MCErrorMessage.h" + #import "MCOConstants.h" +#import "NSObject+MCO.h" -static NSString * MCOLocalizedDescriptionTable[] = { - @"The operation succeeded.", /** MCOErrorNone */ - @"A stable connection to the server could not be established.", /** MCOErrorConnection */ - @"The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ - @"Unable to parse response from server.", /** MCOErrorParse */ - @"The certificate for this server is invalid.", /** MCOErrorCertificate */ - @"Unable to authenticate with the current session's credentials.", /** MCOErrorAuthentication */ - @"IMAP is not enabled for this Gmail account.", /** MCOErrorGmailIMAPNotEnabled */ - @"Bandwidth limits were exceeded while requesting data from this Gmail account.", /** MCOErrorGmailExceededBandwidthLimit */ - @"Too many simultaneous connections were made to this Gmail account.", /** MCOErrorGmailTooManySimultaneousConnections */ - @"MobileMe is no longer an active mail service.", /** MCOErrorMobileMeMoved */ - @"Yahoo!'s servers are currently unavailable.", /** MCOErrorYahooUnavailable */ - @"The requested folder does not exist. Folder selection failed", /** MCOErrorNonExistantFolder */ - @"An error occured while renaming the requested folder.", /** MCOErrorRename */ - @"An error occured while deleting the requested folder.", /** MCOErrorDelete */ - @"An error occured while creating the requested folder.", /** MCOErrorCreate */ - @"An error occured while (un)subscribing to the requested folder.", /** MCOErrorSubscribe */ - @"An error occured while appending a message to the requested folder.", /** MCOErrorAppend */ - @"An error occured while copying a message to the requested folder.", /** MCOErrorCopy */ - @"An error occured while expunging a message in the requested folder.", /** MCOErrorExpunge */ - @"An error occured while fetching messages in the requested folder.", /** MCOErrorFetch */ - @"An error occured during an IDLE operation.", /** MCOErrorIdle */ - @"An error occured while requesting the server's identity.", /** MCOErrorIdentity */ - @"An error occured while requesting the server's namespace.", /** MCOErrorNamespace */ - @"An error occured while storing flags.", /** MCOErrorStore */ - @"An error occured while requesting the server's capabilities.", /** MCOErrorCapability */ - @"The server does not support STARTTLS connections.", /** MCOErrorStartTLSNotAvailable */ - @"Attempted to send a message with an illegal attachment.", /** MCOErrorSendMessageIllegalAttachment */ - @"The SMTP storage limit was hit while trying to send a large message.", /** MCOErrorStorageLimit */ - @"Sending messages is not allowed on this server.", /** MCOErrorSendMessageNotAllowed */ - @"The current HotMail account cannot connect to WebMail.", /** MCOErrorNeedsConnectToWebmail */ - @"An error occured while sending the message.", /** MCOErrorSendMessage */ - @"Authentication is required for this SMTP server.", /** MCOErrorAuthenticationRequired */ - @"An error occured while fetching a message list on the POP server.", /** MCOErrorFetchMessageList */ - @"An error occured while deleting a message on the POP server.", /** MCOErrorDeleteMessage */ - @"Account check failed because the account is invalid.", /** MCOErrorInvalidAccount */ - @"File access error", /** MCOErrorFile */ - @"Compression is not available", /** MCOErrorCompression */ - @"A sender is required to send message", /** MCOErrorNoSender */ - @"A recipient is required to send message", /** MCOErrorNoRecipient */ - @"An error occured while performing a No-Op operation.", /** MCOErrorNoop */ - @"An application specific password is required", /** MCOErrorGmailApplicationSpecificPasswordRequired */ -}; +using namespace mailcore; @implementation NSError (MCO) + (NSError *)mco_errorWithErrorCode:(mailcore::ErrorCode)code { @@ -59,8 +21,11 @@ static NSString * MCOLocalizedDescriptionTable[] = { NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; if ((NSInteger) code < MCOErrorCodeCount) { - NSString * localizedString = NSLocalizedStringFromTable(MCOLocalizedDescriptionTable[code], @"description of errors of mailcore", @"MailCore"); - [userInfo setObject:localizedString forKey:NSLocalizedDescriptionKey]; + String * errorMessage = errorMessageWithErrorCode(code); + if (errorMessage != NULL) { + NSString * localizedString = NSLocalizedStringFromTable(MCO_TO_OBJC(errorMessage), @"description of errors of mailcore", @"MailCore"); + [userInfo setObject:localizedString forKey:NSLocalizedDescriptionKey]; + } } NSError *error = [NSError errorWithDomain:MCOErrorDomain -- cgit v1.2.3