如何从PHP中的电子邮件中提取身体部位?

时间:2017-09-01 14:21:02

标签: java php

这是我在PHP中的功能,我想提取电子邮件的正文部分。函数接受一个msg类型为 MimeMessage 的对象。 我想从此消息中提取body部分然后将其转换为String,然后将此String与另一个String连接,然后将此最终连接的String添加到另一个新对象的主体中,该对象的类型为 newMsg 也是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()');
}

我想添加类似 newMsg.setBody(bodyText)

的内容

注意:我不确定给定Function中的MimeMessage类型是Java对象还是PHP对象,因为函数声明是PHP格式。

0 个答案:

没有答案
相关问题