I am using vmime to try and parse the attached documents and emails to do some custom changes to the attached emails.
In this scenario, I want to be able to change the emails on the fly, perhaps copying the references of bodyparts/body into another message and changing the corresponding headers.
Current state:
I am able to read the email, parse the contents and decipher if it has an attachment email.
This is a code snippet:
###########################################################################
/**
is called recursivels, for all the body parts that have to
be processed
**/
int32_t
ProcessAttachmentPart(std::shared_ptr<vmime::bodyPart> inBodyPart,
std::shared_ptr<vmime::bodyPart> outBodyPart,
int32_t depth)
{
auto header = inBodyPart->getHeader();
if (header->hasField(vmime::fields::CONTENT_TYPE))
{
auto field = header->getField(std::string(vmime::fields::CONTENT_TYPE));
auto partType = field->getValue()->generate();
if (partType == "message/rfc822" == 0)
{
/**
---------------> problem here <-----------------
If this is a sub-message, I have not parsed this message
when I called Message::parse() somewhere before.
How to I get a handle to this message now???
**/
ApplyBodyTransformation( inBodyPart->getBody(),
outBodyPart->getBody());
}
else
{
CopyBodyPart(inBodyPart, outBodyPart);
}
}
else
{
CopyBodyPart(inBodyPart, outBodyPart);
}
ProcessHeaders(inBodyPart, outBodyPart);
return 0;
}
int32_t
ApplyBodyTransformation(const std::shared_ptr<vmime::body> inBody,
std::shared_ptr<vmime::body> outBody)
{
for (auto part : inBody->getPartList())
{
std::shared_ptr<vmime::bodyPart> outBodyPart(new vmime::bodyPart);
ProcessAttachmentPart(part, outBodyPart,depth);
outBody->appendPart(outBodyPart);
}
return 0;
}
###############################################################################
What I could do
-- is to call the function inBodyPart->generate(<into a file>)
-- read file into new message
-- parse and attach the new message in to the final message.
What I want to do is NOT to write this additional file..
I cannot find any such API in the code..
Any help would be appreciated.
Regards,
Ashish