我在将钥匙串互联网密码与使用Applescript创建的Mail.app电子邮件帐户相关联时遇到一些问题。我不想使用“set password to”Applescript命令,因为我希望我的应用程序能够保持对我创建的keychain条目的访问。
所以这基本上就是我在做的事情:
1)按如下方式创建钥匙串条目:
SecTrustedApplicationRef objApp[2];
CFArrayRef arrApps;
SecAccessRef objAccess;
SecKeychainItemRef objKeychainItem;
SecProtocolType nProtocolType;
::SecTrustedApplicationCreateFromPath (NULL,&objApp[0]);
::SecTrustedApplicationCreateFromPath ("/Applications/Mail.App",
&objApp[1]);
arrApps = ::CFArrayCreate (kCFAllocatorDefault,(const void **) &objApp,
2,NULL);
::SecAccessCreate (CFSTR ("mail.myserver.com",arrApps,&objAccess);
nPort = 0;
nProtocolType = kSecProtocolTypePOP3;
SecKeychainAttribute objAttrList[] = {
{ kSecLabelItemAttr, 17, (char *) "mail.myserver.com" },
{ kSecAccountItemAttr, 20, (char *) "someone@myserver.com" },
{ kSecServerItemAttr, 17, (char *) "mail.myserver.com" },
{ kSecPortItemAttr, sizeof (int), &nPort },
{ kSecProtocolItemAttr, sizeof (SecProtocolType), &nProtocolType }
};
SecKeychainAttributeList objAttributes =
{ sizeof (objAttrList) / sizeof (objAttrList[0]),
objAttrList
};
::SecKeychainItemCreateFromContent (kSecInternetPasswordItemClass,
&objAttributes,
12, "somepassword"
NULL,
objAccess,&objKeychainItem);
2)使用Applescript创建一个帐户:
tell application "Mail"
set newacct to make new pop account with properties
{ name:"someone@myserver.com",
user name:"someone@myserver.com",
uses ssl:true,
server name:"mail.myserver.com",
authentication: password,
port:995,
full name:"Someone",
email addresses:{"someone@myserver.com"}
}
end tell
两个部分都单独工作,但Mail不会将钥匙串条目与创建的帐户相关联。我一定是错过了一步,但我看不到它,所以任何帮助都会受到赞赏。