MailCore 2 Documentation

repository·master·Indexed 25 days ago

https://github.com/mailcore/mailcore2

An 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.

Tokens
8.5K
Snippets
9
Records
61
Agent score
82%

What's inside MailCore 2

  1. Overview of MailCore 2

    master
    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.
  2. Configure MailCore 2 for iOS (Static Library)

    master

    To target iOS, you must link against MailCore 2 as a static library:

    1. Add libMailCore-ios.a to 'Link Binary With Libraries'.
    2. Add CFNetwork.framework and Security.framework to 'Link Binary With Libraries'.
    3. In Build Settings, set 'C++ Standard Library' to libc++.
    4. In Build Settings, set 'Other Linker Flags' to: -lctemplate-ios -letpan-ios -lxml2 -lsasl2 -liconv -ltidy -lz -lc++ -lresolv -stdlib=libc++ -ObjC
    5. In Build Phases, add a Target Dependency of static mailcore2 ios.
  3. Build MailCore 2 for Android from source

    master

    To 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_NDK and ANDROID_SDK to your local root folders.

    Important Note: Ensure the mailcore2 repository 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/sdk
  4. Download MailCore 2 Windows binaries

    master

    If 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:

  5. Compile dependencies for Android build

    master

    Follow these steps to compile the required dependencies:

    1. OpenSSL:

      • Navigate to build-android/dependencies/openssl.
      • Edit build.sh line 4 to use the latest 1.0.2xxx version (e.g., 1.0.2u).
      • Run ./build.sh. (Note: Some errors regarding stdlib.h or .a files can be ignored if openssl-android-3.zip is generated and contains header files).
    2. iconv:

      • Navigate to build-android/dependencies/iconv.
      • Run ./build.sh.
    3. cyrus-sasl:

      • Navigate to build-mac/dependencies.
      • Edit prepare-cyrus-sasl.sh line 5 to set version=2.1.26.
      • Run ./prepare-cyrus-sasl.sh (wait until "building tools" is printed).
      • Navigate to build-android/dependencies/cyrus-sasl.
      • Run ./build.sh.
    4. libetpan:

      • Run ./autogen && make to generate libetpan-config.h (ignore make errors).
      • Navigate to build-android.
      • Edit jni/Android.mk: Remove -DHAVE_ICONV=1 from LOCAL_CFLAGS (line 131) to build without iconv.
      • Run ./build.sh.
  6. Configure Device Identity for ActiveSync Sessions

    master

    For most use cases, you do not need to set a deviceID explicitly. ActiveSyncSession (C++) and MCOActiveSyncSession (ObjC) will automatically generate a stable default deviceID if 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 that deviceType is no longer publicly configurable; the session internally uses MailCore.

  7. Install dependencies for building MailCore 2 on Linux

    master

    To 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 libtool
  8. Install MailCore 2 via Swift Package Manager

    master

    Add MailCore 2 to your Xcode project using Swift Package Manager:

    1. In Xcode, go to File -> Swift Packages -> Add Package Dependency....
    2. Enter the URL: https://github.com/MailCore/mailcore2.
    3. Under Rules, select Branch and set it to master.
    4. Complete the wizard by clicking Next and Finish.

    Note for Xcode 12 users: If you encounter issues with Xcode 12, you must perform these additional steps:

    1. Select your project and target, then go to Build Phases.
    2. Click + and select New Copy Files Phase. Set the Destination to Frameworks.
    3. Click + and select New 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"
  9. Shrink MailCore .aar file size

    master

    To reduce the .aar file size by approximately 50%, follow these steps in the directory containing mailcore2-android-4.aar:

    1. Unzip the .aar to a temporary directory.
    2. Remove the jni folder from the extracted classes.jar.
    3. Re-package the classes.jar and the .aar file.
    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
  10. Use MailCore 2 in Swift projects

    master

    To use MailCore 2 in a Swift project, you must set up an Objective-C Bridging Header:

    1. Create a new header file named [Project-Name]-Bridging-Header.h.
    2. Add the following import to the file: #import <MailCore/MailCore.h>
    3. In your target settings, locate the Objective-C Bridging Header field 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.