使用 Apple Scripting Bridge 和 Mail 发送附件会导致消息背景变黑

发布于 2024-09-06 04:02:30 字数 2110 浏览 3 评论 0原文

当我使用 Apple Scripting Bridge 发送带有附件的消息时,消息的背景设置为黑色,这是一个问题,因为文本也是黑色的。有问题的代码是:

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];

/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
 initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
 emailSubject, @"subject",
 [self composeEmailBody], @"content", nil]];

/* add the object to the mail app  */
[[mail outgoingMessages] addObject: emailMessage];

/* set the sender, show the message */
emailMessage.sender = [NSString stringWithFormat:@"%@ <%@>",[[[mail accounts] objectAtIndex:playerOptions.mailAccount] fullName],[[[[mail accounts] objectAtIndex:playerOptions.mailAccount] emailAddresses] objectAtIndex:0]];
emailMessage.visible = YES;

/* create a new recipient and add it to the recipients list */
MailToRecipient *theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
 initWithProperties:
 [NSDictionary dictionaryWithObjectsAndKeys:
  opponentEmail, @"address",
  nil]];
[emailMessage.toRecipients addObject: theRecipient];

/* add an attachment, if one was specified */
if ( [playerInfo.gameFile length] > 0 ) {

    /* create an attachment object */
    MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      playerInfo.gameFile, @"fileName", nil]];

    /* add it to the list of attachments */
    [[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];

背景颜色的实际更改发生在倒数第二行,即:

[[emailMessage.content attachments] addObject: theAttachment];

上面的代码部分本质上是从 Apple 的 SBSendMail 示例代码中提取的。在这个阶段,我实际上只进行了与应用程序中的数据集成所需的更改。如果我在从 Apple 新鲜下载后构建并运行 SBSendMail 示例,则执行同一行后消息背景也会更改为黑色。附加哪种类型的文件、位于何处、使用哪台计算机或操作系统似乎并不重要。

这可能是苹果脚本桥中的一个错误,但有人遇到过这个问题并找到了解决方案吗?或者,有谁知道是否可以使用脚本桥更改 MailOutgoingMessage 实例的背景颜色?

When I use the Apple Scripting Bridge to send a message with an attachment the background of the message is set to black which is a problem because the text is also black. The code in question is:

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];

/* create a new outgoing message object */
MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
 initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
 emailSubject, @"subject",
 [self composeEmailBody], @"content", nil]];

/* add the object to the mail app  */
[[mail outgoingMessages] addObject: emailMessage];

/* set the sender, show the message */
emailMessage.sender = [NSString stringWithFormat:@"%@ <%@>",[[[mail accounts] objectAtIndex:playerOptions.mailAccount] fullName],[[[[mail accounts] objectAtIndex:playerOptions.mailAccount] emailAddresses] objectAtIndex:0]];
emailMessage.visible = YES;

/* create a new recipient and add it to the recipients list */
MailToRecipient *theRecipient =
[[[mail classForScriptingClass:@"to recipient"] alloc]
 initWithProperties:
 [NSDictionary dictionaryWithObjectsAndKeys:
  opponentEmail, @"address",
  nil]];
[emailMessage.toRecipients addObject: theRecipient];

/* add an attachment, if one was specified */
if ( [playerInfo.gameFile length] > 0 ) {

    /* create an attachment object */
    MailAttachment *theAttachment = [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      playerInfo.gameFile, @"fileName", nil]];

    /* add it to the list of attachments */
    [[emailMessage.content attachments] addObject: theAttachment];
}
/* send the message */
[emailMessage send];

The actual change to the background colour occurs on the second last line, which is:

[[emailMessage.content attachments] addObject: theAttachment];

The code sections above are essentially lifted from the SBSendMail example code from Apple. At this stage I've really only made the changes necessary to integrate with the data from my application. If I build and run the SBSendMail example after freshly downloading it from Apple the message background is also changed to black with execution of the same line. It does not appear to matter which type of file is attached, where it is located, or on which computer or operating system is used.

This could be a bug in Apple's scripting bridge but has anyone come across this problem and found a solution? ALternatively does anyone know if the background colour of a MailOutgoingMessage instance can be changed with the scripting bridge?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小苏打饼 2024-09-13 04:02:30

我不认为问题出在你的代码中。我认为这是最近出现的一个错误。对这个问题的快速谷歌搜索发现了这个: http ://discussions.apple.com/thread.jspa?threadID=2453797&start=0&tstart=0

I don't think the problem is in your code. I think it's a bug that recently popped up. A quick google search for this issue turned up this: http://discussions.apple.com/thread.jspa?threadID=2453797&start=0&tstart=0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文