Wednesday, December 31, 2014

Keep Calm and Email On: Using OS X Mail to Send Through iCloud Uses TLS Even Though UI Says No

I was looking through the Account Info screen of OS X 10.10 Yosemite’s and the red alert 🚨 sounded in my head because sending mail using the iCloud SMTP server my account is configured for didn’t appear to be using SSL:

Screen Shot 2014 12 31 at 12 27 05 PM

I immediately asked AppleCare to call me. I didn’t want to waste any time figuring this out, I wanted to know how to fix it. As soon as I put my number in the web form, I got a call. Then I got connected immediately to a person. Apple has this part of the customer service experience nailed.

The guys I talked to at AppleCare were great. The first guy I talked didn’t waste my time with scripts. As soon as I described my issue he knew what I was talking about & had me try resetting my account in System Preferences Internet Accounts. When that didn’t work, he escalated to a guy named “Chris”. 

While on hold, I did some digging of my own. I found the iCloud SMTP server config in ~/Library/Preferences/MobileMeAccounts.plist. Here’s the section on the iCloud SMTP server:


Looks like SSL is required, but the UI isn’t showing it. What’s going on? I turned on logging in Mail’s Connection Doctor and captured this log while sending a test mail out (bolds mine):

INITIATING CONNECTION Dec 31 11:39:39.264 -- port:587 -- socket:0x0 -- thread:0x618000a69b40
CONNECTED Dec 31 11:39:39.375 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
READ Dec 31 11:39:39.553 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
220 -- Server ESMTP (Oracle Communications Messaging Server 64bit (built Aug 27 2014))
WROTE Dec 31 11:39:39.562 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
READ Dec 31 11:39:39.653 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
250-XLOOP 1EAF97A4D9D382EFF77592D25EA741DA
250 SIZE 28311552
WROTE Dec 31 11:39:39.653 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
READ Dec 31 11:39:39.749 [kCFStreamSocketSecurityLevelNone] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
220 2.5.0 Go ahead with TLS negotiation.
WROTE Dec 31 11:39:40.088 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
READ Dec 31 11:39:40.187 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
250-XLOOP 1EAF97A4D9D382EFF77592D25EA741DA
250 SIZE 28311552
WROTE Dec 31 11:39:40.188 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
AUTH ATOKEN (*** 80 bytes hidden ***)
READ Dec 31 11:39:40.291 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
235 2.7.0 ATOKEN authentication successful.
WROTE Dec 31 11:39:40.292 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
MAIL FROM:<redacted>
READ Dec 31 11:39:40.399 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
250 2.5.0 Address Ok.
WROTE Dec 31 11:39:40.399 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
RCPT TO:<redacted>
READ Dec 31 11:39:40.744 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
250 2.1.5 redacted OK.
WROTE Dec 31 11:39:40.744 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
READ Dec 31 11:39:40.833 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
354 Enter mail, end with a single ".".
WROTE Dec 31 11:39:40.833 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
From: Dave Murdock <redacted>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Subject: Test Mail
Message-Id: <>
Date: Wed, 31 Dec 2014 11:39:39 -0500
To: Dave Murdock <redacted>
Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\))
X-Mailer: Apple Mail (2.1993)
READ Dec 31 11:39:41.042 [kCFStreamSocketSecurityLevelTLSv1_0] -- -- port:587 -- socket:0x6100004a5460 -- thread:0x618000a69b40
250 2.5.0 Ok, envelope id is negotiating for TLS using STARTTLS. Technically, the UI is correct, SSL/TLS is not guaranteed but negotiated. Mail data wasn’t exchanged until TLS had been negotiated, so everything is fine, except the UI is misleading.

I thought SMTPS(ecure) required a dedicated port, but TLS is expected to be negotiated over port 587 (or another if in use). Wikipedia has a good summary.

“Chris” at AppleCare confirmed what was going on and called the account summary screen a “display” bug, which he would file with engineering.

Just for fun, we tried adding the iCloud SMTP server defaulting to, not negotiated, TLS, but it didn’t work. Turns out with 2 factor authentication, you can’t add the iCloud SMTP server directly, it constantly reports that it can’t authenticate.

Tuesday, December 30, 2014

Productivity Booster: Drag Files from OS X Finder to Attachment Buttons in Safari

I have no idea how long this has existed, but I just discovered you can drag a file* from Finder on OS X onto a file attachment button in Safari and It Just Works™!

This is going to save me serious time on  Bug Reporter:

Screen Shot 2014 12 30 at 11 34 17 AM

* Does not work with multiple files

Saturday, July 12, 2014

Amazon iOS App Showing Android App in Search Results

Totally feels like a passive aggressive dick move and from a UX standpoint, obviously not what's wanted.

Friday, July 11, 2014

How To Have Xcode Automatically Delete an iOS Simulator Content Folder When Building Your App

Inspired by Matt ConeyBeare's post Programmatically Opening the iOS Simulator Data Directory for Your App, I've written a shell script, with Matt's script as a template, to delete an app's content folder in the iOS simulator with every build. I needed this while testing the content download startup code for an app I'm working on.

To use the script create an Xcode Run Script Build Phase for the target(s) where you want it to run and paste in the following:

Note: Yes
is redundant, but did not want to introduce confusion about what shell.

Thursday, June 26, 2014

Why Does Apple's Swift Use Pascal's Variable Declaration Syntax?

I'm extremely excited about Swift. I’ve read The Swift Programming Language and Using Swift with Cocoa and Objective-C. Both were very well written and explained with clear examples what you can do with Swift, but left out information I'm dying to know: why?

Not why does Swift exist, I think it's pretty obvious that Apple's Objective-C, which along with AppKit dates to 1988, was showing its age. C itself is from the late 60s, early 70s. A language purportedly as fast as C with non-garbage collected but automatic memory management (mostly) and protection against common programmer mistakes has been needed for a while now. No we need the why of Swift's design.

Why was Swift Designed the Way It Is?

That's the missing link for me in both Swift books. Some might argue that explaining why Swift is designed the way it is requires a third book. I would have found it much easier to digest some syntax design if those decisions had been explained inline. Especially when that syntax is largely used from another non-C like language.

For example, Swift uses Pascal's variable declaration syntax, but not its constants declaration syntax.


Pascal Variables
var one = 1;
var two: Integer = 2;
Swift Variables
var three = 3
var four: Int = 4
Pascal Constants
const five = 5;
const six: Integer = 6;
Swift Constants
let seven = 7
let eight: Integer = 8

Why Happened To Objective-C Without the C?

If the goal was Objective-C without the C, then the up to Xcode 6 Beta 2 Swift syntax seems kind of far way from that. Chris Pietschmann has a good Basic Comparison of C# and Apple Swift Programming Language Syntax. I haven't used C# in a few years, so this was a nice refresher:

C# Variables
var legalAge = 18;
string firstName;

C# Constants
const int legalAge = 18;

Looks a lot more like Objective-C without the C. There is a rough edge there. C# didn't have a var keyword in early versions. So explicitly typed variables start with the type name, not var. Var is only for method local scope implicitly typed variables.

An important idea here is that C# looks an awful lot like C++ without the second +. C++ Intrinsic type variables and constant declaration looks identical to C# (ignoring C++ 2011 additions since it post dates core C#, and C#'s var keyword). The main difference is C# class variables have no pointers.

Here are a few possible versions of an alternative universe variable declaration syntax in Swift following C# and C++, but would sand away the C# var rough edge:

Swift Alt 1
var:String lastName = "Kirk"

//Traditional C constant keyword
const:Int rulesBroken = 4

//A new C like constant keyword whose length matches var
con:Int rulesBroken = 4
Swift Alt 2
var String lastName = "Spock"

//Traditional C constant keyword
const Int rulesBroken = 4 

//A new C like constant keyword whose length matches var
con Int rulesBroken = 4

What I like about these examples is the connection of type with the kind of variable. It makes the code more readable as a sentence to me:

//With type
variable of type String named Kirk

//Without type
variable named Kirk
Instead of Swift's current syntax: 

//With type
variable named Kirk of type String

//Without type
variable named Kirk
I introduced a new constant declaration keyword con anticipating that the use of let was due in part to wanting length matched keywords for variables and constants. I dislike let which reads weird to me in non-declaration cases (more on that in another post) and it's meaning compatible with JavaScript. Perhaps there's a compiler land reason why name:type is better, I don't know because it's not explained.

Maybe there is an across Swift consistency reason for the use of keyword(s) name:type = default

Unified Theory for Swift's Variable Declaration Syntax

Swift & LLVM lead designer Chris Lattner is obviously a C++ wizard since LLVM is written in it. He must also have seen and likely used a lot of C# since he was a Research Intern at Microsoft's Research lab. He didn't adopt C# or slightly modified C++ variable declaration syntax. Why not?
In the absence of an official explanation, I have a theory. Look at function and closure declarations in Swift:

Swift Functions and Closures
func backwards(s1: String, s2: String) -> Bool {
    return s1 > s2

reversed = sort(names, { (s1: String, s2: String) -> Bool in
    return s1 > s2
By default all parameters are constants, so let is ommitted. What remains? In the majority case, name: type.

My theory is that Swift uses the Pascal variable declaration syntax to make reading functions and closures with constant parameters easier for people.

At worst, the the function & closure parameter declaration syntax can expand to this keyword(s) name: type. Examples:

//keyword(s) name: type

func fullName(var middleName: String) -> String

func lastName(inout lastName: String) -> String

{ (firstName: String) -> String in return firstName.description }
Contrast with a couple functions in C#

void addReferenceType(SomeRefType refType) {
    // do something

void SwapStrings(ref string s1, ref string s2) {
    // The string parameter is passed by reference. 
    // Any changes on parameters will affect the original variables.

    string temp = s1;
    s1 = s2;
    s2 = temp;
    System.Console.WriteLine("Inside the method: {0} {1}", s1, s2);
C# can make the position of the parameter name position 2 or 3 after each comma, but can result in some method signatures that are possibly more jagged than Swift.

Why Else Would Swift Use Pascal Variable Declaration Syntax?

If the Pascal variable declaration syntax isn't for the compiler or it really doesn't make functions & closures more readable, I don't know why it was chosen. Personal taste? Just to be different than C#?

Obviously the LLVM and Swift team at Apple are brilliant people. I have immense respect for the amazing work they've been doing to modernize the platform. But it seems like there was a more familiar path from Objective-C to Swift for variable declaration and it wasn't taken. I'd love to know why.

Tuesday, April 15, 2014

Are You Hangry?

Hunger + Angry = Hangry

Nothing brings out Hangry like a vacation. Everyone's eating schedules thrown out, sleep deprived, sunburned and hungover.

Watch out!

Carnival Cruise Ship Can't Handle The Windows XPiration

I don't know why the ship map channel running Windows XP surprises me, but it did this morning:

Friday, April 04, 2014

Xcode 5.1 Expired Provisioning Profile Hidden Feature

In Xcode 5.0.x, you could not delete multiple expired provisioning profiles by multiple selecting the expired profiles. Highly annoying if a development device acquired a ton of these things over years of testing.

In Xcode 5.1, you finally can select multiple expired profiles and delete! Sometimes it really is the little things...