yamime
Complete Rust port of Go's
mimepackage with async-first design
A comprehensive MIME handling library for Rust, providing full support for MIME type detection, media type parsing, multipart messages, quoted-printable encoding, and RFC 2047 encoded-words. Built with async/await and tokio for modern Rust applications.
Features
- ๐ฏ MIME Type Detection - File extension to MIME type mapping with 1000+ built-in types
- ๐ Media Type Parsing - RFC 2045/2616/2231 compliant media type handling
- ๐ฎ Multipart Messages - Full multipart/form-data and multipart/mixed support
- ๐ค Encoded Words - RFC 2047 encoded-word encoding/decoding for email headers
- โ๏ธ Quoted-Printable - RFC 2045 quoted-printable encoding/decoding
- โก Async First - Built on tokio for high-performance async I/O
- ๐ฆ Pure Rust - No unsafe code, fully type-safe
- ๐งช Well Tested - 121+ tests with 73.78% code coverage
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
MIME Type Detection
use type_by_extension;
// Get MIME type by file extension
let mime_type = type_by_extension;
assert_eq!;
let mime_type = type_by_extension;
assert_eq!;
Media Type Parsing
use parse_media_type;
let = parse_media_type.unwrap;
assert_eq!;
assert_eq!;
Multipart Form Data
use Writer;
use AsyncWriteExt;
async
Reading Multipart Data
use Reader;
use AsyncReadExt;
async
Quoted-Printable Encoding
use Writer;
use AsyncWriteExt;
async
Encoded Words (Email Headers)
use ;
// Encoding
let encoder = QEncoding;
let encoded = encoder.encode;
println!;
// Output: =?UTF-8?q?Hello,_=E4=B8=96=E7=95=8C!?=
// Decoding
let decoder = new;
let decoded = decoder.decode.unwrap;
assert_eq!;
API Overview
Core Modules
mime_type- MIME type detection and extension mappingmedia_type- Media type parsing and formatting (RFC 2045/2616/2231)multipart- Multipart message handling (RFC 2046/2388)Reader- Parse multipart messagesWriter- Create multipart messagesForm- Multipart form data support
quotedprintable- Quoted-printable encoding (RFC 2045)Reader- Decode quoted-printableWriter- Encode quoted-printable
encoded_word- RFC 2047 encoded-word supportWordEncoder- Encode headersWordDecoder- Decode headers
error- Error types and result definitions
Platform Support
The library includes platform-specific MIME type loading:
- Unix/Linux/macOS - Loads from
/etc/mime.typesand other standard locations - Windows - Reads from Windows Registry
Performance
The library includes comprehensive benchmarks using Criterion:
Example benchmark results:
- Media type parsing: ~125 ns per operation
- Quoted-printable encoding (1KB): ~45 ยตs (22 MiB/s)
- Multipart writing (5 parts): ~150 ยตs
Testing
Run Tests
# All tests (121+ tests)
# Unit tests only
# Integration tests
# With coverage
Test Coverage
Current test coverage: 73.78% (695/942 lines)
- โ error.rs: 100%
- โ mime_type.rs: 97%
- โ encoded_word.rs: ~88%
- โ quotedprintable/writer.rs: ~85%
- โ multipart/writer.rs: 81%
See TESTING_GUIDE.md for detailed testing documentation.
Fuzzing
The project includes fuzz tests using cargo-fuzz:
# Install cargo-fuzz
# Run fuzzing (examples)
Examples
See the examples/ directory for more complete examples:
basic_mime_type.rs- MIME type detectionmultipart_form.rs- Creating multipart formsemail_headers.rs- Encoding email headersfile_upload.rs- Handling file uploads
Run examples:
Comparison with Other Libraries
| Feature | yamime | mime | mailparse |
|---|---|---|---|
| MIME type detection | โ | โ | โ |
| Media type parsing | โ | โ | โ |
| Multipart messages | โ | โ | โ |
| Quoted-printable | โ | โ | โ |
| Encoded words (RFC 2047) | โ | โ | โ |
| Async/await | โ | โ | โ |
| Form data | โ | โ | โ |
| Writing support | โ | โ | โ |
Requirements
- Rust: 1.70 or later
- Tokio: 1.35 or later (async runtime)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
# Clone the repository
# Run tests
# Run benchmarks
# Check formatting
# Run clippy
Guidelines
- Write tests for new features
- Maintain or improve code coverage
- Follow Rust naming conventions
- Add documentation for public APIs
- Run
cargo fmtbefore committing
License
This project is dual-licensed under:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Acknowledgments
- Inspired by Go's
mimepackage - Built with tokio async runtime
- Tested with Criterion benchmark framework
- Fuzzed with cargo-fuzz
Resources
RFCs Implemented
- RFC 2045 - MIME Part One: Format of Internet Message Bodies
- RFC 2046 - MIME Part Two: Media Types
- RFC 2047 - MIME Part Three: Message Header Extensions
- RFC 2231 - MIME Parameter Value and Encoded Word Extensions
- RFC 2388 - Returning Values from Forms: multipart/form-data
- RFC 2616 - HTTP/1.1 (Media Type handling)
Made with โค๏ธ in Rust