Menu

problem in reading mail from imap store using vmime

Help
2013-09-11
2013-09-13
  • omkar phadke

    omkar phadke - 2013-09-11

    bellow is sample code
    It reads mails from mailstore and write into temporary file and compare with original file.
    problem is : header is present in email files in mailstore but when we read mails from imapstore then it does not read headers so mail comparison fails.

    Platform is Rhel6
    Vmime rpm is libvmime-0.9.2-0.1.20110626svn.el6.x86_64

    sample code :

    bool testStoreAttachmentMail::validateOriginalMailStoredToAttachmentMaster(string& szWorkingCopy,AttachmentMailAccessBean& oAttachmentMailAccessBean)
    {
    // create the imap store connection to the attachment master user
    // get the first mail to the attachment store user i.e. last mail added to the user
    // compare the mail retrieved and the mail given for the test case
    bool bValid = false;
    try
    {
    // connect to the store
    vmime::ref <vmime::net::session> sess = vmime::create <vmime::net::session>();

        string szStoreUrl = "imap://";
        szStoreUrl.append(oAttachmentMailAccessBean.getAttachmentMasterUser());
        szStoreUrl.append(":");
        szStoreUrl.append(oAttachmentMailAccessBean.getAttachmentMasterPassword());
        szStoreUrl.append("@");
        szStoreUrl.append(oAttachmentMailAccessBean.getAttachmentMasterMailStoreIP());
    
        vmime::utility::url storeURL(szStoreUrl);
        vmime::ref <vmime::net::store> store = sess->getStore(storeURL);
        store->connect();
    
        // Open the INBOX of the attachment master user
        vmime::ref <vmime::net::folder> folder = store->getDefaultFolder();
        folder->open (vmime::net::folder::MODE_READ_WRITE);
    
        int iMessageCount = folder->getMessageCount();
    
        // get the latest mail stored in the attachment master's mailstore
        vmime::ref <vmime::net::message> msg = folder->getMessage(iMessageCount);
    
        ofstream myout;
    
        string szFilename = szWorkingCopy + "_retrieved_mail";
    
        try
        {
            myout.open(szFilename.c_str(),  ios::out );
    
            if( myout.is_open() )
            {
                if(m_oLogger->isDebugEnabled())
                {
                    DEBUG(m_oLogger, "[StoreAttachmentMail(store)] opened File name: " + szFilename );
                }
            }
            else
            {
                ERROR(m_oLogger, "[StoreAttachmentMail(store)] could not open File name: " + szFilename );
            }
        }
        catch ( std::exception &e )
        {
            ERROR(m_oLogger,"[StoreAttachmentMail(store)] Exception while storing the attachment file : " + (string)e.what() );
        }
    
        // Here, extract() will actually download message data from the server
        vmime::utility::outputStreamAdapter out(myout);
        msg->extract(out);
    
        myout.flush();
        myout.close();
    
        // compare both the files to validate that same mail has been copied
        bValid = cmpFiles(szWorkingCopy,szFilename);
    
        if ( (remove(szFilename.c_str())) == -1 )
        {
            WARN(m_oLogger,"[testStoreAttachmentMail] - <Error while deleting message file, it may not be present " + szFilename ) ;
        }
    }
    catch ( string error )
    {
        ERROR(m_oLogger,"[StoreAttachmentMail(store)] Exception while storing the attachment file : " + (string)error );
    }
    return bValid ;
    

    }

     
  • Vincent Richard

    Vincent Richard - 2013-09-11

    Hi!

    As far as I remember, it may be a bug in extract() function. I can only advise you to use a newer version of VMime.

    Unfortunately, there is not recently released package, but you can get the latest sources from the GitHub repository: https://github.com/kisli/vmime

    Vincent

     
  • omkar phadke

    omkar phadke - 2013-09-13

    ok, thanks for help Richard.

     

Log in to post a comment.