尝试阅读 multipart/signed 邮件时,原始附件被忽略,仅显示 smime.7ps 文件

While trying to read a multipart/signed mail, the original attachments are ignored and only smime.7ps file is displayed

我正在尝试连接到邮箱并阅读邮件和附件。这里当有任何带有数字签名的邮件时,只读取 smime.7ps 文件,而忽略其他(xml,pdf 等)。我可以观察到,在此类邮件中,只有邮件的签名部分会被读取,正文部分会被忽略。我在这里使用 Multipart。请让我知道是否有任何不同的处理方式可以帮助我读取带有数字签名的邮件的正文附件?这是我的代码的一部分,它获取 messages/attachments:

    if (contentType.contains("multipart")){
            Multipart multiPart = (Multipart) message.getContent();
            int numberOfParts = multiPart.getCount();
            for (int partCount = 0; partCount < numberOfParts; partCount++) {
                MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
                if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
                    // this part is attachment
                    String fileName = part.getFileName();

                    attachFiles += fileName + ", ";
                    part.saveFile(SaveDirectory + File.separator + fileName);


                } else {
                    // this part may be the message content
                    messageContent = part.getContent().toString();
                }
            }

            if (attachFiles.length() > 1) {
                attachFiles = attachFiles.substring(0, attachFiles.length() - 2);
            }
            //}
        } else if (contentType.contains("text/plain") || contentType.contains("text/html")) {
            Object content = message.getContent();
            if (content != null) {
                messageContent = content.toString();
            }
        }

谢谢香农!您输入的嵌套多部分实际上帮助我解决了问题!

MimeMultipart 多部分 = (MimeMultipart) message.getContent(); //* 阅读电子邮件及其内容*

//***Your code for Different actions with Email Message
int numberOfParts = multiPart.getCount();
for (int partCount = 0; partCount < numberOfParts; partCount++) {

    //***Reading Body Part contents from the Email Message
    MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
        //***Your Code for Different actions with Body part contents

        //***Now the below step would help you to check if the above retrieved content(part) is having any further multiparts nested in it. 
        //***Once the check is true, then you can instantiate that content again as a multipart and retrieve the related details.
        if(part.getContent() instanceof Multipart){ 
            Multipart multipart = (Multipart) part.getContent();
            for (int j = 0; j < multipart.getCount(); j++) {
                 MimeBodyPart bodyPart = (MimeBodyPart)multipart.getBodyPart(j);
            }
        }
}