This is my function which is in PHP and I want to extract Body Part of the email message. The Function accepts an object which is msg whose type is MimeMessage. I want to extract body part from this message then convert it to a String and then concatenate this String with another String and then add this final concatenated String into the body of an another new object which is newMsg whose type is also MimeMessage.
private function handleQuestion(MimeMessage msg)
{
$this->log->debug('ListProcessor: Entered handleQuestion()');
$this->log->info('Processing Question: ' + getMsgLogInfo(msg));
// To handle a question just send it on to the list server.
// It will take care of the rest of the processing.
try
{
// Ensure that this question didn't come from the staging mailbox.
// This could cause an e-mail loop situation.
String stagingAddress=(String)$this->runConfig.get('stagingMailboxAddress');
FromStringTerm fromSearch = new FromStringTerm(stagingAddress);
if (fromSearch.match(msg))
{
$this->log->warn('Message sent from staging mailbox: sending to admin');
sendToListAdmin(msg, MSGERR_FROM_STAGING);
}
else
{
// String msgSubject = msg.getSubject();
// String subject = translateRFC2231Subject(msgSubject);
String subject = translateRFC2231Subject(getSubjectLines(msg));
// Create a new message, initialized using the one from the mailbox
MimeMessage newMsg = new MimeMessage((MimeMessage)msg);
// Redirect it to the List Server
newMsg.setRecipient(Message.RecipientType.TO,
new InternetAddress((String)runConfig.get('publicListAddress')));
// Remove any CC/BCC addresses
newMsg.setRecipients(Message.RecipientType.CC, '');
newMsg.setRecipients(Message.RecipientType.BCC, '');
newMsg.setSubject(subject);
mailTransport.send(newMsg);
// Update the threadTracker.
InternetAddress author = (InternetAddress)msg.getFrom()[0];
MessageThreadData threadData = new MessageThreadData((InternetAddress)author, new Date());
threadTracker.put(subject.trim(), threadData);
$this->log->info('Started New Thread: ' + getMsgLogInfo(msg));
$this->newThreadCount++;
$this->log->info('Question Processed Successfully');
}
}
catch (Exception ex)
{
$this->errorCount++;
$this->log->error('Question Processing Failed', ex);
}
$this->log->debug('ListProcessor: Exiting handleQuestion()');
}
I want to add something like newMsg.setBody(bodyText)
Note: I am not sure whether MimeMessage type in the given Function is a Java object or PHP object because the function declaration is in the PHP form.