Created
October 18, 2012 17:54
-
-
Save andrewzimmer906/3913753 to your computer and use it in GitHub Desktop.
Search for mail by subject using libetpan for iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This function searches a mailimap session for messages with a certain string in their subject line, and returns those messages udid numbers. NOTE: This is called synchronously, so do it in a background thread. | |
*/ | |
+(NSArray*)searchFolderForString:(NSString*)string withFolderSession:(struct mailimap *)session { | |
if([string length] == 0) { | |
return nil; | |
} | |
int err; | |
const char *charset = [@"UTF-8" cStringUsingEncoding:NSUTF8StringEncoding]; | |
const char *search = [string cStringUsingEncoding:NSUTF8StringEncoding]; | |
clist * fetch_result = NULL; | |
struct mailimap_search_key *searchKey = mailimap_search_key_new_subject((char *)search); | |
err = mailimap_uid_search(session, charset, searchKey, &fetch_result); | |
if(err != MAIL_NO_ERROR) { | |
NSLog(@"Error searching mailbox"); | |
return nil; | |
} | |
int len = clist_count(fetch_result); | |
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:len]; | |
clistiter *fetchResultIter = clist_begin(fetch_result); | |
for(int i=0; i<len; i++) { | |
uint32_t * mes = (uint32_t*)clist_content(fetchResultIter); | |
[tempArray addObject:[NSNumber numberWithUnsignedInt:*mes]]; | |
fetchResultIter = clist_next(fetchResultIter); | |
} | |
clist_free(fetch_result); | |
return [NSArray arrayWithArray:tempArray]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment