Archived Forum Post

Index of archived forum posts

Question:

Save as EML (IMAP) vs. Signed-Info

Nov 08 '13 at 06:29

Hi there, currently i am trying to look for all unseen mails in the Mailbox and save them as mime. I am not sure how to go on from the received messageSet with fetchSingleAsMime() :-/

Here is a snipped from the (example)code:

// Select an IMAP mailbox success = imap.SelectMailbox(imapfolder);

if (success != true) 
{
    MessageBox(imap.lastErrorText());
          return;
}

// CkMessageSet *messageSet = 0; bool fetchUids; fetchUids = true;

//  Find emails marked as unseen:
const char * notSeenSearch;
notSeenSearch = "NOT SEEN";

//  Get the set of unseen message UIDs
messageSet = imap.Search(notSeenSearch,fetchUids);
if (messageSet == 0 )
{
    MessageBox(imap.lastErrorText());
        return;
}

//... this is where i would need to store each unseen email as mime.eml so all info like //signed by & encryption etc. is still

//in it.Was thinking about to use this somehow -> mimeStr = imap.fetchSingleAsMime(i,bUid);

I would be very happy if someone could Show me how to go on from here!


Answer

The CkMessageSet API is fairly straightforward.

See http://www.chilkatsoft.com/refdoc/vcCkMessageSetRef.html

You can get the number of message ID's in the CkMessageSet via the Count property. You can tell whether the message set contains sequence numbers or UID's via the HasUids property, and then you can get each ID by index via the GetId method. Just write a simple loop:

CkImap imap;
CkMessageSet *mset = 0;

// get the mset via a call to imap.Search

bool bHasUids = mset->get_HasUids();

int count = mset->get_Count();
int i;
for (i=0; i<count; i++)
    {
    int id = mset->GetId(i);

const char *mimeStr = imap.fetchSingleAsMime(id,bHasUids);

}

delete mset;

Answer

Not sure if my solution is an option as well, or if I should keep using it this way:

Because I need CkEMail and the CkEmailBundle plus the option for CkStringArray->SaveToFile, I did as follows (please feel free to correct me if this is a bad Option):

CkEmailBundle* bundle=0;
bundle = imap.FetchBundle(*messageSet);

CkStringArray* bundlex;
bundlex = imap.FetchBundleAsMime(*messageSet);

CkEmail* email = 0;

long i;
    for (i = 0; i <= bundle->get_MessageCount() - 1; i++) 
    {
//...working with it here
email = bundle->GetEmail(i);
bundlex->SaveToFile(myfilename);
}