在 Mail.app 插件中以编程方式读取和更改 to/cc/bcc 字段
有没有人成功地找到了更改 Mail.app 插件中传出消息的收件人、抄送和密件抄送字段的方法?我一直在查看头文件,试图弄清楚我需要做什么才能获取邮件收件人列表,并能够更改它们(具体来说,删除一些收件人并将其余收件人切换为密件抄送)。
注意:我知道我需要在哪里找到如何做到这一点,但我已经花了一些时间在这上面,并且有很多不同的类可以做到这一点,并且所需的猜测量是不小的。我只是希望有人过去已经经历过这个,可以让我免于重复的努力。
Has anyone ever successfully figured out the method to alter the to, cc and bcc fields of an outgoing message in a Mail.app plugin? I've been looking through the header files trying to figure out exactly what I need to do to get the list of recipients of the message, and have the ability to alter them (specifically, to remove some recipients and switch the remaining recipients to be bcc'ed).
Note: I know where I would need to look to find out how to do this, but I've spent some time on that and there are a lot of different classes that do this and the amount of guesswork needed is nontrivial. I'm merely hoping someone has gone through this already in the past and can save me from the duplicate effort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了!
用于撰写消息的窗口是 MailDocumentEditor,它继承自 DocumentEditor。 DocumentEditor 有一个名为 _headersEditor 的实例变量,它是一个 HeadersEditor 对象。
HeadersEditor 具有 to、cc 和 bcc 字段的实例变量,分别命名为 _toField、_ccField 和 _bccField。这些是 AddressTextField 的实例。
有一些方法可以获取已输入到 AddressTextField 中的地址。如果您熟悉“邮件”,地址可以通过几种不同的方式显示在此处。有些只是纯文本地址,有些是地址簿条目的标记(因此它们显示为带有名称的标记,您可以右键单击以获取电子邮件地址)。您可以为 NSMutableArray*s _stringsWithNoRecords 和 _stringsAwaitingRecords 以及 NSMutableDictionary* _recordsForStrings 创建访问器。
但是,要设置这些字段的地址,请使用 initTextCell:(NSString *) 创建一个 NSCell,并在这些字段中包含您想要的电子邮件地址。然后,调用 AddressTextField 上的 setCell: 方法。这将用 NSCell 中的 NSString 替换该字段的内容。
Figured it out!
The window that you use to compose a message is a MailDocumentEditor, which inherits from DocumentEditor. DocumentEditor has an instance variable called _headersEditor which is a HeadersEditor object.
HeadersEditor has instance variables for the to, cc and bcc fields, named _toField, _ccField and _bccField, respectively. These are instances of AddressTextField.
There are methods that can get you the addresses that have been entered into the AddressTextField. If you are familiar with Mail, addresses can appear in here in a few different ways. Some are just plain text addresses, some are tokens for address book entries (so they show up as tokens with the name, which you can right-click to get the email address). You can create accessors for the NSMutableArray*s _stringsWithNoRecords and _stringsAwaitingRecords, as well as the NSMutableDictionary* _recordsForStrings.
However, to set the addresses of these fields, create an NSCell using initTextCell:(NSString *) with the email addresses you want in these fields. Then, call the setCell: method on the AddressTextField. This will replace the contents of that field with your NSString in the NSCell.