MailCore 2 Documentation
repository·master·Indexed 25 days ago
https://github.com/mailcore/mailcore2An asynchronous API for working with IMAP, POP, and SMTP protocols. It primarily targets iOS and macOS developers, with additional support for Android, Linux, and Windows platforms. The library depends on libetpan and provides installation guides for Swift Package Manager, Carthage, CocoaPods, and manual builds from source.
What's inside MailCore 2
- MailCore 2 is an asynchronous Objective-C API for interacting with email protocols including IMAP, POP, and SMTP. It features an RFC822 parser and generator, supports HTML rendering of messages, and is designed for iOS and Mac platforms.
Configure MailCore 2 for iOS (Static Library)
masterTo target iOS, you must link against MailCore 2 as a static library:
- Add
libMailCore-ios.ato 'Link Binary With Libraries'. - Add
CFNetwork.frameworkandSecurity.frameworkto 'Link Binary With Libraries'. - In
Build Settings, set 'C++ Standard Library' tolibc++. - In
Build Settings, set 'Other Linker Flags' to:-lctemplate-ios -letpan-ios -lxml2 -lsasl2 -liconv -ltidy -lz -lc++ -lresolv -stdlib=libc++ -ObjC - In
Build Phases, add a Target Dependency ofstatic mailcore2 ios.
- Add
Build MailCore 2 for Android from source
masterTo build MailCore 2 on macOS, follow these steps in exact order.
Prerequisites:
- libetpan: Download version 1.9.4 from GitHub. Ensure the path contains no spaces.
- Android NDK: Version 17.
- Android SDK: Versions 16 and 21.
- Environment Variables: Set
ANDROID_NDKandANDROID_SDKto your local root folders.
Important Note: Ensure the
mailcore2repository path contains no spaces to avoid compilation errors.export ANDROID_NDK=/Users/xxx/Library/Android/sdk/ndk/17.2.4988734 export ANDROID_SDK=/Users/xxx/Library/Android/sdkDownload MailCore 2 Windows binaries
masterIf you only require a pre-compiled binary build of MailCore 2, you can download it directly. Note that all provided binaries are compiled in release mode. For debug mode, you must download the source repositories and compile them manually.
Required Dependencies: You must also download the most recent binary builds for the following dependencies:
Compile dependencies for Android build
masterFollow these steps to compile the required dependencies:
OpenSSL:
- Navigate to
build-android/dependencies/openssl. - Edit
build.shline 4 to use the latest1.0.2xxxversion (e.g.,1.0.2u). - Run
./build.sh. (Note: Some errors regardingstdlib.hor.afiles can be ignored ifopenssl-android-3.zipis generated and contains header files).
- Navigate to
iconv:
- Navigate to
build-android/dependencies/iconv. - Run
./build.sh.
- Navigate to
cyrus-sasl:
- Navigate to
build-mac/dependencies. - Edit
prepare-cyrus-sasl.shline 5 to setversion=2.1.26. - Run
./prepare-cyrus-sasl.sh(wait until "building tools" is printed). - Navigate to
build-android/dependencies/cyrus-sasl. - Run
./build.sh.
- Navigate to
libetpan:
- Run
./autogen && maketo generatelibetpan-config.h(ignoremakeerrors). - Navigate to
build-android. - Edit
jni/Android.mk: Remove-DHAVE_ICONV=1fromLOCAL_CFLAGS(line 131) to build without iconv. - Run
./build.sh.
- Run
Download MailCore 2 Android Binary
masterIf you do not wish to build from source, you can download the latest pre-built Android binary from the following location:
Configure Device Identity for ActiveSync Sessions
masterFor most use cases, you do not need to set a
deviceIDexplicitly.ActiveSyncSession(C++) andMCOActiveSyncSession(ObjC) will automatically generate a stable defaultdeviceIDif none is provided. This ensures that server policy and sync state remain stable across app launches.If you require deterministic migration, testing, or specific product identifiers, you can manually override the
deviceID. Note thatdeviceTypeis no longer publicly configurable; the session internally usesMailCore.Install dependencies for building MailCore 2 on Linux
masterTo build MailCore 2 on a Debian-based Linux system, you must first install the required development packages using
apt-get.sudo apt-get install libctemplate-dev libicu-dev libsasl2-dev libtidy-dev \ uuid-dev libxml2-dev libglib2.0-dev autoconf automake libtoolInstall MailCore 2 via Swift Package Manager
masterAdd MailCore 2 to your Xcode project using Swift Package Manager:
- In Xcode, go to
File->Swift Packages->Add Package Dependency.... - Enter the URL:
https://github.com/MailCore/mailcore2. - Under
Rules, selectBranchand set it tomaster. - Complete the wizard by clicking
NextandFinish.
Note for Xcode 12 users: If you encounter issues with Xcode 12, you must perform these additional steps:
- Select your project and target, then go to
Build Phases. - Click
+and selectNew Copy Files Phase. Set theDestinationtoFrameworks. - Click
+and selectNew Run Script Phase. Paste the following script to ensure the framework is signed correctly:
if [ "$PLATFORM_NAME" == "macosx" ] then FRAMEWORK_PATH="$CODESIGNING_FOLDER_PATH"/Contents/Frameworks/MailCore.framework/Versions/A/MailCore else FRAMEWORK_PATH="$CODESIGNING_FOLDER_PATH"/Frameworks/MailCore.framework fi echo "Signing framework at: $FRAMEWORK_PATH" /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$FRAMEWORK_PATH"- In Xcode, go to
Compile MailCore 2 on Linux
masterOnce the dependencies and
libetpanare installed, you can compile MailCore 2 usingcmakeandmakewithin abuilddirectory inside the MailCore 2 source folder.cd ~/mailcore2 mkdir build cd build cmake .. makeShrink MailCore .aar file size
masterTo reduce the
.aarfile size by approximately 50%, follow these steps in the directory containingmailcore2-android-4.aar:- Unzip the
.aarto a temporary directory. - Remove the
jnifolder from the extractedclasses.jar. - Re-package the
classes.jarand the.aarfile.
unzip mailcore2-android-4.aar -d mailcore-unzipped rm mailcore2-android-4.aar cd mailcore-unzipped unzip classes.jar -d classes-unzipped rm -rf classes-unzipped/jni rm classes.jar jar cvf classes.jar -C classes-unzipped/ . rm -rf classes-unzipped cd .. jar cvf mailcore2-android-4.aar -C mailcore-unzipped/ . rm -rf mailcore-unzipped- Unzip the
Use MailCore 2 in Swift projects
masterTo use MailCore 2 in a Swift project, you must set up an Objective-C Bridging Header:
- Create a new header file named
[Project-Name]-Bridging-Header.h. - Add the following import to the file:
#import <MailCore/MailCore.h> - In your target settings, locate the
Objective-C Bridging Headerfield and provide the path to your header file.
Once configured, you do not need to manually import MailCore in your Swift classes; it will be available automatically.
- Create a new header file named