MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.61k stars 627 forks source link

Mailcore 2 can not access gmail messages except Inbox folder #303

Closed bhushan12 closed 11 years ago

bhushan12 commented 11 years ago

With Mailcore 2 I am able to access Yahoo's almost all folders but when try for gmail , it can only access Inbox folder. Please anyone know whats going wrong.

abhinavguptas commented 11 years ago

I would suggest trying out this call and print out all folders coming in NSArray "folders", see if the folder you are trying to access comes up here.

    [[MCOIMAPSession fetchAllFoldersOperation] start:^(NSError *error, NSArray *folders) ;
bhushan12 commented 11 years ago

I am getting all folders calling "fetchAllFoldersOperation". But when I try to fetch messages from 'sent' or 'trash' or anything except Inbox folder, I am getting null messages array.

abhinavguptas commented 11 years ago

Can you please share your minified code sample, along with folder name you are passing in message fetch operation.

bhushan12 commented 11 years ago

here is my code.. if ([dict count] > 0) { myAccountsession = [[MCOIMAPSession alloc] init]; [myAccountsession setHostname:[dict objectForKey:@"incomingserver"]]; [myAccountsession setPort:993]; [myAccountsession setUsername:[dict objectForKey:@"email"]]; [myAccountsession setPassword:[dict objectForKey:@"password"]]; [myAccountsession setConnectionType:MCOConnectionTypeTLS]; } MCOIMAPMessagesRequestKind requestKind = (MCOIMAPMessagesRequestKind) (MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure | MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject | MCOIMAPMessagesRequestKindFlags); NSString *folder = foldernamestring; //foldernamestring is fetched from folders array from previous ViewController. NSLog(@"foldername to fetch mails %@",folder); imapMessagesFetchOp =[myAccountsession fetchMessagesByNumberOperationWithFolder:foldernamestring requestKind:requestKind numbers:[MCOIndexSet indexSetWithRange:fetchRange]];

         [imapMessagesFetchOp setProgress:^(unsigned int progress) {
             NSLog(@"Progress: %u", progress);
         }];
         [imapMessagesFetchOp start:
          ^(NSError *error, NSArray *messages, MCOIndexSet *vanishedMessages)
          {
              //here i should get messages
           }];
abhinavguptas commented 11 years ago

What is your "fetchRange" variable value, via this code snippet its the only guy I can see as trouble. One suggestion would be to try for all messages in folder via MCORange fetchRange = MCORangeMake(1, UINT64_MAX);

bhushan12 commented 11 years ago

Thanks @abhinavguptas I have done that already. That code is just to provide how many messages to fetch, it should not be a problem. But why I am able to fetch all folders in Yahoo but not of gmail. I changed imap.gmail.com to various protocols but no success. any clue....

abhinavguptas commented 11 years ago

humm, last thing I would suggest is printing out error variable which comes in callback block, you might have tried that.

And, enable connectionLogger to see what IMAP commands are flowing over the wire, its sometimes helpful

    [imapSession setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data){
        DLog(@"MCOIMAPSession: [%i] %@", type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
    }];
bhushan12 commented 11 years ago

hi, I tried 'setConnectionLogger' and I got below log

MCOIMAPSession: [0] 4 NO [NONEXISTENT] Unknown Mailbox: Sent Mail (Failure)

Its only 'Unknown Mailbox' I could understand as trouble, any ideas?.. I am passing 'Sent Mail' as folder name..

dinhvh commented 11 years ago

If it's Gmail, Sent Mail folder is usually "[Gmail]/Sent Mail" or something similar.

bhushan12 commented 11 years ago

That worked really well. Thank you both of you @abhinavguptas and @dinhviethoa , I was manipulating folder names to make it readable and was passing same. Now I am getting messages but when I use 'folderInfoOperation' to calculate MCORange fetchrange (like in mailcore 2 iOSUITest example) befor fetching messages, I do not get any messages.

dinhvh commented 11 years ago

a connectionLogger would be useful to help analyze what's going on?

Hoà V. Dinh

On Monday, August 12, 2013 at 11:12 PM, bhushan12 wrote:

That worked really well. Thank you both of you @abhinavguptas (https://github.com/abhinavguptas) and @dinhviethoa (https://github.com/dinhviethoa) , I was manipulating folder names to make it readable and was passing same. Now I am getting messages but when I use 'folderInfoOperation' to calculate MCORange fetchrange (like in mailcore 2 iOSUITest example) befor fetching messages, I do not get any messages.

— Reply to this email directly or view it on GitHub (https://github.com/MailCore/mailcore2/issues/303#issuecomment-22545081).

bhushan12 commented 11 years ago

connectionLogger gives following Log,

MCOIMAPSession: [1] 3 SELECT "[Gmail]/Drafts" MCOIMAPSession: [0] * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)

dinhvh commented 11 years ago

Could you show the kind of code you use? FETCH 5906112:47406368 looks wrong. I think the range you passed is wrong. You probably want to debug to know which range you passed.

bhushan12 commented 11 years ago

Right my fetchRange is NULL. Working on it. Thanks @dinhviethoa )

VishnuPrem55 commented 1 year ago

I have fetched all mailcore folder names. please check the given link,

https://github.com/MailCore/mailcore2/issues/912#issuecomment-1323276900