BodyStructureBuilder is a Java library that builds BODYSTRUCTURE responses according to RFC3501 (IMAP protocol). It parses MIME messages and generates the corresponding IMAP BODYSTRUCTURE format that can be used in IMAP server implementations.
- RFC3501 Compliant: Generates BODYSTRUCTURE responses that conform to the IMAP protocol specification
- MIME Support: Handles various MIME types including:
- Multipart messages (multipart/alternative, multipart/mixed, multipart/report, etc.)
- Text messages
- Message/rfc822 (embedded messages)
- Other MIME media types
- Extension Support: Optional inclusion of BODYSTRUCTURE extensions (MD5, Content-Disposition, Content-Language, Content-Location)
- Simple API: Easy-to-use static utility method
- Efficient: Built with performance in mind using streaming and buffering
- Java 11 or higher
- Maven 3.x
- Apache MIME4J (0.8.13) - MIME message parsing
- Jakarta Mail (1.6.8) - Mail API support
- SLF4J (1.7.29) - Logging facade
- Lombok (1.18.40) - Code generation
Add the following repository configuration to your pom.xml:
<repositories> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>https://nexus.manty.co.kr/repository/maven-releases/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>https://nexus.manty.co.kr/repository/maven-snapshots/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
Add the following dependency to your pom.xml:
<dependency> <groupId>kr.co.manty.mail.imap</groupId> <artifactId>bodystructurebuilder</artifactId> <version>1.0.1</version> </dependency>
import kr.co.manty.mail.imap.bodystructure.BodyStructureBuilder; import java.io.InputStream; // Read MIME message from input stream InputStream mimeInputStream = ...; // Build BODYSTRUCTURE with extensions byte[] bodyStructure = BodyStructureBuilder.build(mimeInputStream, true); // Build BODYSTRUCTURE without extensions byte[] bodyStructure = BodyStructureBuilder.build(mimeInputStream, false);
// Read an .eml file InputStream mimeInputStream = getClass().getResourceAsStream("/eml/test1.eml"); // Generate BODYSTRUCTURE byte[] bodyStructure = BodyStructureBuilder.build(mimeInputStream, true); // Use the result (e.g., send as IMAP response) String bodyStructureString = new String(bodyStructure);
mvn testThe test suite includes examples for:
- Multipart alternative messages
- Multipart mixed messages
- Multipart report messages
src/main/java/kr/co/manty/mail/imap/bodystructure/
├── BodyStructureBuilder.java # Main entry point
├── BodyStructureEncoder.java # Encodes structure to IMAP format
├── BodyStructureComposer.java # Composes IMAP response
├── MimeDescriptorStructure.java # Structure implementation
├── Structure.java # Structure interface
└── mime/ # MIME parsing components
For more information about the author, visit: https://www.manty.co.kr
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Copyright 2024 Manty Co., Ltd.