Open alexcosmin opened 8 years ago
I think you need to set the client ID (IMAP ID) when talking to qq mail.
First, thank you for the quick reply.
I understood that I should try something like this:
//configure my _imapSession like I did above
MCOIMAPIdentity *identity = [MCOIMAPIdentity identityWithVendor:@"SomeVendor" name:@"SomeName" version:@"1.0.1"];
MCOIMAPIdentityOperation *identityOperation = [_imapSession identityOperationWithClientIdentity:identity];
[identityOperation start:^(NSError * error, NSDictionary * serverIdentity) {
if (error && !serverIdentity) {
NSLog(@"Error sending identity: %@", error);
} else {
NSLog(@"Successfully sent identity.");
}
}];
//use the same _imapSession object for the 'imapCheckOperation' that I want to perform
That sounds good, but the problem is that I get an error EXC_BAD_ACCESS (code=1)
when trying to initialise the MCOIMAPIdentity
. So at this line:
MCOIMAPIdentity *identity = [MCOIMAPIdentity identityWithVendor:@"SomeVendor" name:@"SomeName" version:@"1.0.1"];
Here's a screenshot:
Seems like the MCOIMAPIdentity
is nil
after the initialisation, therefore [MCOIMAPIdentity setVendor:]
fails when trying to access something that's not in memory anymore (or at least that's how I understand it).
I also tried the other way around, same result. No matter which setVersion
, setName
, setVendor
I call first.
MCOIMAPIdentity *identity = [[MCOIMAPIdentity alloc] init];
[identity setVersion:@"1.0.1"];
[identity setName:@"SomeName"];
[identity setVendor:@"SomeVendor"];
I tried searching for older issues relating to MCOIMAPIdentity
and I found this one #1151. Is it correct that the identity
is released? Maybe that's causing it.
Or maybe autorelease
shouldn't be used in the implementation of MCOIMAPIdentity.
Any thoughts on this? Note: I'm using the 0.5.1 version of MailCore2.
Could you show a stack trace of the crash please? There's also a clientIdentity property on the MCOIMAPSession that you can mutate.
Mutating the clientIdentity
property was the first thing that I've tried after your initial response.
Turns out that it's readonly
as trying this:
_imapSession.clientIdentity = [MCOIMAPIdentity identityWithVendor:@"SomeVendor" name:@"SomeName" version:@"1.0.1"];
Results in Assignment to readonly property
error in Xcode, preventing it from compiling.
And it is indeed declared readonly
in MCOIMAPSession.h
:
/** The identity of the IMAP client. */
@property (nonatomic, strong, readonly) MCOIMAPIdentity * clientIdentity;
Is that on purpose?
Working on getting the stack trace.
Please try: [_imapSession clientIdentity] .vendor = something;
.
The stack trace for the crash:
* thread #1: tid = 0x1669e7, 0x00000001000d8bfc MailPOC`-[MCOIMAPIdentity setVendor:](self=<unavailable>, _cmd=<unavailable>, vendor=@"SomeVendor") + 48 at MCOIMAPIdentity.mm:66, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x00000001000d8bfc MailPOC`-[MCOIMAPIdentity setVendor:](self=<unavailable>, _cmd=<unavailable>, vendor=@"SomeVendor") + 48 at MCOIMAPIdentity.mm:66
frame #1: 0x00000001000d8f64 MailPOC`+[MCOIMAPIdentity identityWithVendor:name:version:](self=<unavailable>, _cmd=<unavailable>, vendor=<unavailable>, name=@"SomeName", version=@"1.0") + 108 at MCOIMAPIdentity.mm:90
frame #2: 0x0000000100092c98 MailPOC`-[ViewController configureImapSession](self=0x000000014c52c2c0, _cmd="configureImapSession") + 428 at ViewController.m:94
frame #3: 0x000000010009291c MailPOC`-[ViewController rightBarButtonTapped:](self=0x000000014c52c2c0, _cmd="rightBarButtonTapped:", sender=0x000000014c69cbd0) + 92 at ViewController.m:69
frame #4: 0x0000000187acbe50 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 100
frame #5: 0x0000000187c4f4a4 UIKit`-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 168
frame #6: 0x0000000187acbe50 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 100
frame #7: 0x0000000187acbdcc UIKit`-[UIControl sendAction:to:forEvent:] + 80
frame #8: 0x0000000187ab3a88 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 416
frame #9: 0x0000000187ab3bd4 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 748
frame #10: 0x0000000187acb6e4 UIKit`-[UIControl touchesEnded:withEvent:] + 572
frame #11: 0x0000000187acb314 UIKit`-[UIWindow _sendTouchesForEvent:] + 804
frame #12: 0x0000000187ac3e30 UIKit`-[UIWindow sendEvent:] + 784
frame #13: 0x0000000187a944cc UIKit`-[UIApplication sendEvent:] + 248
frame #14: 0x0000000187a92794 UIKit`_UIApplicationHandleEventQueue + 5528
frame #15: 0x0000000182d58efc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #16: 0x0000000182d58990 CoreFoundation`__CFRunLoopDoSources0 + 540
frame #17: 0x0000000182d56690 CoreFoundation`__CFRunLoopRun + 724
frame #18: 0x0000000182c85680 CoreFoundation`CFRunLoopRunSpecific + 384
frame #19: 0x0000000184194088 GraphicsServices`GSEventRunModal + 180
frame #20: 0x0000000187afcd90 UIKit`UIApplicationMain + 204
frame #21: 0x0000000100094518 MailPOC`main(argc=1, argv=0x000000016fd73b08) + 124 at main.m:14
frame #22: 0x00000001828268b8 libdyld.dylib`start + 4
I tried your proposal:
[_imapSession clientIdentity].vendor = @"SomeVendor";
[_imapSession clientIdentity].name = @"SomeName";
[_imapSession clientIdentity].version = @"1.0";
NSLog(@"Vendor: %@",_imapSession.clientIdentity.vendor);
The NSLog
shows that the vendor
was set properly. There's no crash now.
But I get the same authentication error:
Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.}
I tried with all 3 IMAP Hostname values that I mentioned above, same result.
Could you show the full connection logs?
Yes, here is the connection log (same as before) when trying to authenticate to a QQ mail account:
2016-01-12 22:29:20.172 MailPOC[3621:1534078] event logged:0x1555a7d80 0 withData: * OK [CAPABILITY IMAP4 IMAP4rev1 IDLE XAPPLEPUSHSERVICE ID UIDPLUS AUTH=LOGIN NAMESPACE] QQMail IMAP4Server ready
2016-01-12 22:29:20.179 MailPOC[3621:1534078] event logged:0x1555a7d80 2 withData: 1 LOGIN "correct_account@qq.com" correct_password //modified real data
2016-01-12 22:29:21.093 MailPOC[3621:1534078] event logged:0x1555a7d80 0 withData: (null)
I also tried with a second QQ mail account. Exactly the same results. This is the connection log when trying to authenticate to a Gmail account (all good):
2016-01-12 22:41:37.952 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * OK Gimap ready for requests from 2.110.13.79 5mb77833782lfi
2016-01-12 22:41:37.959 MailPOC[3644:1538952] event logged:0x135eb91b0 1 withData: 1 CAPABILITY
2016-01-12 22:41:38.170 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH
1 OK Thats all she wrote! 5mb77833782lfi
2016-01-12 22:41:38.172 MailPOC[3644:1538952] event logged:0x135eb91b0 2 withData: 2 LOGIN "correct_account@gmail.com" correct_password
2016-01-12 22:41:39.295 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS
2 OK correct_account@gmail.com authenticated (Success)
2016-01-12 22:41:39.295 MailPOC[3644:1538952] event logged:0x135eb91b0 1 withData: 3 COMPRESS DEFLATE
2016-01-12 22:41:39.499 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: 3 OK Success
2016-01-12 22:41:39.500 MailPOC[3644:1538952] event logged:0x135eb91b0 1 withData: 4 ENABLE CONDSTORE
2016-01-12 22:41:39.704 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * ENABLED CONDSTORE
4 OK Success
2016-01-12 22:41:39.705 MailPOC[3644:1538952] event logged:0x135eb91b0 1 withData: 5 NAMESPACE
2016-01-12 22:41:39.909 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * NAMESPACE (("" "/")) NIL NIL
5 OK Success
2016-01-12 22:41:39.909 MailPOC[3644:1538952] event logged:0x135eb91b0 1 withData: 6 ID (version "1.0" name SomeName vendor SomeVendor)
2016-01-12 22:41:40.118 MailPOC[3644:1538952] event logged:0x135eb91b0 0 withData: * ID ("name" "GImap" "vendor" "Google, Inc." "support-url" "https://support.google.com/mail" "version" "gmail_imap_160105.05_p0" "remote-host" "2.110.13.79")
6 OK Success
Additional investigation: I checked that my settings are correct for using IMAP, in the QQ mail settings. Seems like everything is okay. Also this extra level of protection Independent protection is turned OFF.
Also, under Settings->Labs I can see that IMAP is enabled:
Weird thing is that I tried to setup this QQ mail account with the native Mail app on iOS. And it fails. So I went in Settings->Mail->Add Account->Other->Input account info.
Just to make sure I can still connect to the same QQ mail account, I opened the QQ mail iOS app and it works flawless with their app.
I also tried to connect to the same QQ mail account from this iOS app which seems to be using this library for fetching email, as stated here. Same problem, fails with this QQ mail account, works perfect with a Gmail account. Tried some more email apps randomly from the App Store, none could connect to the QQ mail account. Only through the QQ mail iOS app.
I think they whitelist based on the IMAP ID.
Quite possible, yes. So you think that they made it so only their whitelisted apps (or whatever) can fetch emails with IMAP. What I'm thinking to try next is to contact the QQ customer support (or smth similar) as ask them how to configure my QQ mail account with the native iOS Mail app. If they say 'Not possible, just use the QQ mail iOS app', then it's clear that they are whitelisting only what they want and therefore I can give up. Edit: Mailed them at qqimail@tencent.com , pending response.
Really appreciate the help, @dinhviethoa ! Any other ideas on what to try, except what I wrote above?
I think some other people in that list were able to log in on QQ mail using IMAP.
Back to the original issue, do you think you could try a later tag of MailCore to see if things have cleared up? If that still doesn't fix it, can you get me a stack trace and set a breakpoint in +[MCOIMAPIdentity identityWithVendor:name:version:]
?
Login on QQ mail need setting in the webmail,POP or IMAP .And the password should be a client identifier that QQ send to your mobile-phone ,not your email ' password.
So how to get the client identifier
Login on QQ mail need setting in the webmail,POP or IMAP .And the password should be a client identifier that QQ send to your mobile-phone ,not your email ' password.
Should this identifier be entered instead of password? And without spaces? I have four groups of digits like XXXX XXXX XXXX XXXX
@Suncatcher yes,no spaces.
Thanks, finally I was able to log in.
I checked that my settings are correct for using IMAP, in the QQ mail settings. Seems like everything is okay. Also this extra level of protection Independent protection is turned OFF.
How did you detect that independent pass is OFF? I see no indicator in settings. Do they have any sort of English-speaking support at all?
Thanks for the library, it's awesome! Just one small issue I'm having:
I can't seem to be able to authenticate to QQ Mail while using IMAP.
The error I'm getting:
The connection logger outputs:
The IMAP hostnames that I've tried:
imap.qq.com
imap.exmail.qq.com
hwimap.exmail.qq.com
The
MCOConnectionType
that I've tried:MCOConnectionTypeTLS
(fails withError Domain=MCOErrorDomain Code=5
)MCOConnectionTypeStartTLS
(fails withError Domain=MCOErrorDomain Code=1
)MCOConnectionTypeClear
(fails withError Domain=MCOErrorDomain Code=1
)I've only tried to connect with port
993
. I'm absolutely sure that the username and password are correct since I've successfully connected to the same account with:I've read these configuration settings and tried the hostname for QQ mail from here.
Does anyone have any idea about why is my authentication failing? Did anyone successfully authenticate to QQ mail? I've successfully connected and authenticated to Gmail, Yahoo and Hotmail.