Sample code for 30+ languages & platforms
Swift

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let email = CkoEmail()!

    // First, load an email from a file. 
    // Note: an email object may be loaded from a file, or
    // downloaded directly from a POP3 or IMAP server...

    success = email.loadEml(mimePath: "testReceivedHdrs.eml")
    if success != true {
        print("\(email.lastErrorText!)")
        return
    }

    // How many header fields?
    var n: Int
    n = email.numHeaderFields.intValue
    if n > 0 {

        // Display the name and value of each header:
        var i: Int
        var name: String?
        var value: String?
        for i = 0; i <= n - 1; i++ {
            name = email.getHeaderFieldName(index: i)
            value = email.getHeaderFieldValue(index: i)
            print("\(i)")
            print("\(name!)")
            print("\(value!)")

        }

    }


}