{"id":32441339,"url":"https://github.com/nathanborror/swift-mime-generated","last_synced_at":"2025-10-26T01:56:40.277Z","repository":{"id":319126198,"uuid":"1077695640","full_name":"nathanborror/swift-mime-generated","owner":"nathanborror","description":"A generated library, commit messages are the prompts used unless otherwise indicated. Currently using Zed Agent with Sonnet 4.5.","archived":false,"fork":false,"pushed_at":"2025-10-17T16:37:29.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-17T18:29:43.758Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanborror.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-16T15:53:53.000Z","updated_at":"2025-10-17T16:37:33.000Z","dependencies_parsed_at":"2025-10-18T06:02:59.326Z","dependency_job_id":"0e81dac6-fed9-4c70-92af-892cd6a3852b","html_url":"https://github.com/nathanborror/swift-mime-generated","commit_stats":null,"previous_names":["nathanborror/swift-mime-generated"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/nathanborror/swift-mime-generated","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2Fswift-mime-generated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2Fswift-mime-generated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2Fswift-mime-generated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2Fswift-mime-generated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanborror","download_url":"https://codeload.github.com/nathanborror/swift-mime-generated/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2Fswift-mime-generated/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281047750,"owners_count":26435124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-26T01:54:22.477Z","updated_at":"2025-10-26T01:56:40.264Z","avatar_url":"https://github.com/nathanborror.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MIME\n\nA Swift package for parsing MIME formatted multipart data. This library provides a clean, type-safe API for working with MIME messages, making it easy to extract headers, parts, and content from multipart messages.\n\n## Features\n\n- ✅ Parse MIME messages (both multipart and non-multipart) according to RFC 2045 and RFC 2046\n- ✅ Optional MIME-Version header (not required for parsing)\n- ✅ Case-insensitive header access\n- ✅ Support for quoted and unquoted boundaries\n- ✅ Automatic charset detection\n- ✅ Type-safe API with `Sendable` support for Swift 6\n- ✅ Convenient helper methods for common operations\n- ✅ No external dependencies\n\n## Requirements\n\n- iOS 18.0+ / macOS 15.0+\n- Swift 6.2+\n\n## Installation\n\nAdd this package to your project using Swift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/yourusername/swift-mime-generated.git\", from: \"1.0.0\")\n]\n```\n\n## Usage\n\n### Multipart Message Example\n\n```swift\nimport MIME\n\nlet mimeString = \"\"\"\nFrom: sender@example.com\nDate: Mon, 01 Jan 2024 12:00:00 -0800\nContent-Type: multipart/mixed; boundary=\"simple\"\n\n--simple\nContent-Type: text/plain\n\nHello, World!\n--simple\nContent-Type: text/html\n\n\u003ch1\u003eHello, World!\u003c/h1\u003e\n--simple--\n\"\"\"\n\nlet message = try MIMEParser.parse(mimeString)\n\n// Access top-level headers\nprint(message.from)  // \"sender@example.com\"\nprint(message.date)  // \"Mon, 01 Jan 2024 12:00:00 -0800\"\n\n// Access parts\nprint(message.parts.count)  // 2\n\nfor part in message.parts {\n    print(part.contentType)  // \"text/plain\", \"text/html\"\n    print(part.body)\n}\n```\n\n### Non-Multipart Message Example\n\nNon-multipart messages (like `text/plain`, `text/html`, `application/json`, etc.) are automatically treated as a single part:\n\n```swift\nlet simpleMessage = \"\"\"\nFrom: sender@example.com\nTo: recipient@example.com\nSubject: Simple Text Message\nContent-Type: text/plain; charset=\"utf-8\"\n\nThis is a simple text message without multipart formatting.\nIt will be parsed as a single part.\n\"\"\"\n\nlet message = try MIMEParser.parse(simpleMessage)\n\n// Convenient access to body for non-multipart messages\nif let body = message.body {\n    print(body)  // \"This is a simple text message...\"\n}\n\n// Or access via parts array\nprint(message.parts.count)  // 1\nprint(message.parts[0].contentType)  // \"text/plain\"\nprint(message.parts[0].body)  // \"This is a simple text message...\"\n```\n\n### Finding Specific Parts\n\n```swift\n// Find all parts with a specific content type\nlet plainParts = message.parts(withContentType: \"text/plain\")\n\n// Find the first part with a specific content type\nif let htmlPart = message.firstPart(withContentType: \"text/html\") {\n    print(htmlPart.body)\n}\n\n// Check if a message contains a specific content type\nif message.hasPart(withContentType: \"application/json\") {\n    print(\"Message contains JSON data\")\n}\n```\n\n### Accessing Headers\n\nHeaders are case-insensitive:\n\n```swift\n// All of these work (case-insensitive)\nlet contentType1 = message.headers[\"Content-Type\"]\nlet contentType2 = message.headers[\"content-type\"]\nlet contentType3 = message.headers[\"CONTENT-TYPE\"]\n\n// MIME-Version header is optional\nlet mimeVersion = message.mimeVersion  // May be nil\n```\n\nPart-specific headers:\n\n```swift\nlet part = message.parts[0]\nprint(part.contentType)  // \"text/plain\"\nprint(part.charset)      // \"utf-8\"\nprint(part.headers[\"Custom-Header\"])\n```\n\n### Complex Example\n\nHere's a more complex example showing a bookmark tracking system:\n\n```swift\nlet bookmarkData = \"\"\"\nFrom: Nathan Borror \u003czV6nZFTyrypSgXo1mxC02yg6PKeXv8gWpKWa1/AzAPw=\u003e\nDate: Wed, 15 Oct 2025 18:42:00 -0700\nMIME-Version: 1.0\nContent-Type: multipart/bookmark; boundary=\"bookmark\"\n\n--bookmark\nContent-Type: text/book-info\nTitle: Why Greatness Cannot Be Planned\nSubtitle: The Myth of the Objective\nAuthors: Kenneth O. Stanley, Joel Lehman\nISBN-13: 978-3319155234\nPublished: 18 May 2015\nLanguage: en\nPages: 135\n\n--bookmark\nContent-Type: text/quote; charset=\"utf-8\"\nPage: 10\nDate: Thu, 29 May 2025 16:20:00 -0700\n\n\"Sometimes the best way to achieve something great is to stop trying to achieve a particular great thing.\"\n\n--bookmark\nContent-Type: text/note; charset=\"utf-8\"\nPage: 10\nDate: Thu, 29 May 2025 16:20:00 -0700\n\nThis book is turning out to be very cathartic!\n\n--bookmark\nContent-Type: text/progress\nPage: 65\nDate: Wed, 13 Oct 2025 18:42:00 -0700\n\n--bookmark\nContent-Type: text/review; charset=\"utf-8\"\nDate: Wed, 15 Oct 2025 18:42:00 -0700\nRating: 4.5\nSpoilers: false\n\nI enjoyed this book!\n--bookmark--\n\"\"\"\n\nlet message = try MIMEParser.parse(bookmarkData)\n\n// Get book info\nif let bookInfo = message.firstPart(withContentType: \"text/book-info\") {\n    print(bookInfo.headers[\"Title\"])     // \"Why Greatness Cannot Be Planned\"\n    print(bookInfo.headers[\"Authors\"])   // \"Kenneth O. Stanley, Joel Lehman\"\n    print(bookInfo.headers[\"ISBN-13\"])   // \"978-3319155234\"\n}\n\n// Get all quotes\nlet quotes = message.parts(withContentType: \"text/quote\")\nfor quote in quotes {\n    print(\"Page \\(quote.headers[\"Page\"] ?? \"?\"): \\(quote.body)\")\n}\n\n// Get all notes\nlet notes = message.parts(withContentType: \"text/note\")\nfor note in notes {\n    print(note.body)\n}\n\n// Get progress\nif let progress = message.firstPart(withContentType: \"text/progress\") {\n    print(\"Currently on page \\(progress.headers[\"Page\"] ?? \"?\")\")\n}\n\n// Get review\nif let review = message.firstPart(withContentType: \"text/review\") {\n    print(\"Rating: \\(review.headers[\"Rating\"] ?? \"N/A\")\")\n    print(\"Review: \\(review.body)\")\n}\n```\n\n## API Reference\n\n### `MIMEParser`\n\nThe main entry point for parsing MIME messages. Supports both multipart messages (with boundaries) and non-multipart messages.\n\n#### Methods\n\n- `static func parse(_ content: String) throws -\u003e MIMEMessage`\n  - Parses a MIME message from a string\n  - Multipart messages are parsed using the boundary specified in the Content-Type header\n  - Non-multipart messages are treated as a single part containing the entire body\n\n### `MIMEMessage`\n\nRepresents a complete MIME message with headers and parts.\n\n#### Properties\n\n- `headers: MIMEHeaders` - The top-level headers\n- `parts: [MIMEPart]` - The individual parts of the message\n- `body: String?` - The body content for non-multipart messages (returns nil for multipart messages)\n- `from: String?` - The \"From\" header value\n- `to: String?` - The \"To\" header value\n- `subject: String?` - The \"Subject\" header value\n- `date: String?` - The \"Date\" header value\n- `mimeVersion: String?` - The \"MIME-Version\" header value (optional, may be nil)\n- `contentType: String?` - The \"Content-Type\" header value\n\n#### Methods\n\n- `func parts(withContentType contentType: String) -\u003e [MIMEPart]`\n  - Returns all parts with a specific content type\n- `func firstPart(withContentType contentType: String) -\u003e MIMEPart?`\n  - Returns the first part with a specific content type\n- `func hasPart(withContentType contentType: String) -\u003e Bool`\n  - Returns true if any part has the specified content type\n\n### `MIMEPart`\n\nRepresents a single part of a multipart MIME message.\n\n#### Properties\n\n- `headers: MIMEHeaders` - The headers for this part\n- `body: String` - The body content\n- `contentType: String?` - The content type (e.g., \"text/plain\")\n- `charset: String?` - The charset (e.g., \"utf-8\")\n- `decodedBody: String` - The decoded body content\n\n### `MIMEHeaders`\n\nA case-insensitive dictionary for MIME headers.\n\n#### Methods\n\n- `subscript(key: String) -\u003e String?` - Access headers by name (case-insensitive)\n- `func contains(_ key: String) -\u003e Bool` - Check if a header exists\n- Conforms to `Collection`, so you can iterate over headers\n\n### `MIMEError`\n\nErrors that can occur during parsing.\n\n#### Cases\n\n- `invalidFormat` - The MIME message format is invalid\n- `invalidEncoding` - The character encoding is invalid or unsupported\n\n## Testing\n\nRun the test suite:\n\n```bash\nswift test\n```\n\n## License\n\n[Your License Here]\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanborror%2Fswift-mime-generated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanborror%2Fswift-mime-generated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanborror%2Fswift-mime-generated/lists"}