通过密件抄送发送邮件时 MailCore 中的错误
Posted
技术标签:
【中文标题】通过密件抄送发送邮件时 MailCore 中的错误【英文标题】:Bug in MailCore when sending mail through bcc 【发布时间】:2012-08-21 16:05:58 【问题描述】:发送带有以下收据的电子邮件时 至:人A 抄送:人B 密件抄送:personC
这三个人都会收到电子邮件。并且所有收到的电子邮件都会在收据字段中显示 personC。正如我们所知,不应显示密件抄送联系人 personC。为什么会发生这种情况?我正确地将CTCoreMessage
设置为to、cc 和bcc。这是MailCore
框架的错误吗?还是我错过了什么?
提前致谢!
以下是相关代码供大家参考
- (IBAction)buttonSendPressed:(id)sender
[self dismissViewControllerAnimated:YES completion:^
CTCoreMessage *testMsg = [[CTCoreMessage alloc] init];
NSMutableArray *mutArrTos = [NSMutableArray array]; // personA
NSMutableArray *mutArrCcs = [NSMutableArray array]; // personB
NSMutableArray *mutArrBccs = [NSMutableArray array]; // personC
NSLog(@"toContactArr :%@",toContactArr);
if (toContactArr.count>0)
for (NSDictionary *dict in toContactArr)
[mutArrTos addObject:[CTCoreAddress addressWithName:[dict valueForKey:@"name"] email:[dict valueForKey:@"email"]]];
NSLog(@"mutArrRecipients : %@", mutArrTos);
[testMsg setTo:[NSSet setWithArray:mutArrTos]];
if (ccContactArr.count>0)
for (NSDictionary *dict in ccContactArr)
[mutArrCcs addObject:[CTCoreAddress addressWithName:[dict valueForKey:@"name"] email:[dict valueForKey:@"email"]]];
NSLog(@"mutArrRecipients : %@", mutArrCcs);
[testMsg setCc:[NSSet setWithArray:mutArrCcs]];
if (bccContactArr.count>0)
for (NSDictionary *dict in bccContactArr)
[mutArrBccs addObject:[CTCoreAddress addressWithName:[dict valueForKey:@"name"] email:[dict valueForKey:@"email"]]];
NSLog(@"mutArrRecipients : %@", mutArrBccs);
[testMsg setBcc:[NSSet setWithArray:mutArrBccs]];
[testMsg setFrom:[NSSet setWithObject:[CTCoreAddress addressWithName:@"222222" email:@"letibe.xx@gmail.com"]]];
[testMsg setBody:self.textView.text];
[testMsg setSubject:self.textField.text];
DbManager *dbManager = [[DbManager sharedManager] switchDBWithFileName:DBNAME];
User *user = [dbManager getAccount];
NSString *account = user.account;
NSString *pwd = user.password;
NSString *emailType = user.email_type;
NSLog(@"user: %@", user);
NSLog(@"account: %@", account);
NSLog(@"pwd: %@", pwd);
NSLog(@"emailType: %@", emailType);
NSError *error;
BOOL success = [CTSMTPConnection sendMessage:testMsg server:@"smtp.gmail.com" username:@"letibe.xx@gmail.com" password:@"222222" port:25 useTLS:YES useAuth:YES error:&error];
if (!success)
// Present the error
NSLog(@"error: %@", error);
else
NSLog(@"CTSMTPConnection success");
];
【问题讨论】:
【参考方案1】:在阅读了 SMTP 协议之后。我已修改 CTCoreMessage.m
以删除标题中的密件抄送地址,如下所示。那么密件抄送地址就不会打印在接收方了。
CTCoreMessage.m
- (NSString *)render
CTMIME *msgPart = myParsedMIME;
if ([myParsedMIME isKindOfClass:[CTMIME_MessagePart class]])
/* It's a message part, so let's set it's fields */
struct mailimf_fields *fields;
struct mailimf_mailbox *sender = (myFields->fld_sender != NULL) ? (myFields->fld_sender->snd_mb) : NULL;
struct mailimf_mailbox_list *from = (myFields->fld_from != NULL) ? (myFields->fld_from->frm_mb_list) : NULL;
struct mailimf_address_list *replyTo = (myFields->fld_reply_to != NULL) ? (myFields->fld_reply_to->rt_addr_list) : NULL;
struct mailimf_address_list *to = (myFields->fld_to != NULL) ? (myFields->fld_to->to_addr_list) : NULL;
struct mailimf_address_list *cc = (myFields->fld_cc != NULL) ? (myFields->fld_cc->cc_addr_list) : NULL;
// struct mailimf_address_list *bcc = (myFields->fld_bcc != NULL) ? (myFields->fld_bcc->bcc_addr_list) : NULL;
clist *inReplyTo = (myFields->fld_in_reply_to != NULL) ? (myFields->fld_in_reply_to->mid_list) : NULL;
clist *references = (myFields->fld_references != NULL) ? (myFields->fld_references->mid_list) : NULL;
char *subject = (myFields->fld_subject != NULL) ? (myFields->fld_subject->sbj_value) : NULL;
//TODO uh oh, when this get freed it frees stuff in the CTCoreMessage
//TODO Need to make sure that fields gets freed somewhere
// fields = mailimf_fields_new_with_data(from, sender, replyTo, to, cc, bcc, inReplyTo, references, subject);
fields = mailimf_fields_new_with_data(from, sender, replyTo, to, cc, NULL, inReplyTo, references, subject);
[(CTMIME_MessagePart *)msgPart setIMFFields:fields];
return [myParsedMIME render];
【讨论】:
【参考方案2】:看起来问题出在框架本身,因为框架没有显示任何表明密件抄送地址将被隐藏的信息
这只是表明可以将消息设置为密件抄送、抄送和收件人。
我已经将框架挖了 2 英尺,但没有发现任何关于密件抄送的信息表明它将隐藏在接收端...
【讨论】:
我们中国人经常挖3尺XD 我修复了这个错误,请检查我的答案。以上是关于通过密件抄送发送邮件时 MailCore 中的错误的主要内容,如果未能解决你的问题,请参考以下文章
.NET SmtpClient 在使用密件抄送时暴露 10 个电子邮件地址(通过 Mandrill)