{"id":51043762,"url":"https://github.com/floatpane/go-mailpatch","last_synced_at":"2026-06-22T12:02:47.314Z","repository":{"id":362151909,"uuid":"1257392595","full_name":"floatpane/go-mailpatch","owner":"floatpane","description":"Parse git format-patch emails in Go. Commit metadata, [PATCH n/m] series, unified diffs, and diffstat — zero dependencies.","archived":false,"fork":false,"pushed_at":"2026-06-22T02:56:57.000Z","size":59,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-22T04:24:44.713Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mailpatch.floatpane.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/floatpane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","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},"funding":{"github":"floatpane"}},"created_at":"2026-06-02T16:27:40.000Z","updated_at":"2026-06-02T21:28:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/floatpane/go-mailpatch","commit_stats":null,"previous_names":["floatpane/go-mailpatch"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/floatpane/go-mailpatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-mailpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-mailpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-mailpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-mailpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatpane","download_url":"https://codeload.github.com/floatpane/go-mailpatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-mailpatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34647750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"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":"2026-06-22T12:02:46.494Z","updated_at":"2026-06-22T12:02:47.308Z","avatar_url":"https://github.com/floatpane.png","language":"Go","funding_links":["https://github.com/sponsors/floatpane"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# go-mailpatch\n\n**Parse `git format-patch` emails in Go. Commit metadata, `[PATCH n/m]` series, unified diffs, and diffstat — zero dependencies.**\n\n[![Go Version](https://img.shields.io/github/go-mod/go-version/floatpane/go-mailpatch)](https://golang.org)\n[![Go Reference](https://pkg.go.dev/badge/github.com/floatpane/go-mailpatch.svg)](https://pkg.go.dev/github.com/floatpane/go-mailpatch)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/floatpane/go-mailpatch)](https://github.com/floatpane/go-mailpatch/releases)\n[![CI](https://github.com/floatpane/go-mailpatch/actions/workflows/ci.yml/badge.svg)](https://github.com/floatpane/go-mailpatch/actions/workflows/ci.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\n\u003c/div\u003e\n\n`git format-patch` turns commits into email: the subject becomes `[PATCH 2/3] fix the thing`, the author and date become headers, the commit message becomes the body, and the diff follows a `---` separator and a diffstat. `git send-email` mails them; reviewers reply; maintainers run `git am`. `go-mailpatch` reads those messages back into structured Go — author, date, series position, commit message, and a fully parsed diff — **without shelling out to git**.\n\nIt grew out of [matcha](https://github.com/floatpane/matcha)'s developer-mail features (patch review and `git-mail`), pulled into a standalone, git-free, dependency-free library.\n\n## Features\n\n- **Parse one message or a whole mbox.** `Parse` for a single patch, `ParseMbox` for every message in an mbox, `ParseSeries` to group a thread into its cover letter + ordered patches.\n- **Subject intelligence.** `[PATCH]`, `[PATCH 2/3]`, `[RFC PATCH v3 1/4]` — the prefix is parsed into index, total, version, and cover-letter flag, and stripped from the clean subject. Non-patch subjects (`[bug] …`) are left untouched.\n- **Real diff parsing.** Per-file `FileChange` with change type (added/deleted/renamed/copied/modified), old/new paths, file modes, binary detection, and per-line hunks. Add/delete counts and a `DiffStat` come for free.\n- **Standalone diff parser.** `ParseDiff` works on a bare `git diff` with no email around it.\n- **MIME-aware.** Decodes quoted-printable / base64 bodies and RFC 2047 encoded-word headers; digs the `text/plain` part out of multipart mail.\n- **Zero dependencies, never runs git.** Standard library only. It parses; it does not apply. What you do with the result is up to you.\n\n## Install\n\n```bash\ngo get github.com/floatpane/go-mailpatch\n```\n\nRequires Go 1.26+.\n\n## Usage\n\n### Parse a single patch email\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/floatpane/go-mailpatch\"\n)\n\nfunc main() {\n\tp, err := mailpatch.Parse(os.Stdin)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Printf(\"%s \u003c%s\u003e\\n\", p.AuthorName, p.AuthorEmail)\n\tfmt.Printf(\"Subject: %s\\n\", p.Subject)\n\tif p.Series.Total \u003e 0 {\n\t\tfmt.Printf(\"Patch %d of %d (v%d)\\n\",\n\t\t\tp.Series.Index, p.Series.Total, p.Series.Version)\n\t}\n\n\tfor _, f := range p.Files {\n\t\tfmt.Printf(\"  %-8s %s  +%d -%d\\n\",\n\t\t\tf.Type, f.Path(), f.Additions, f.Deletions)\n\t}\n\tfmt.Printf(\"%d files changed, +%d -%d\\n\",\n\t\tp.Stat.FilesChanged, p.Stat.Additions, p.Stat.Deletions)\n}\n```\n\n```console\n$ git format-patch -1 --stdout | go run .\nAda Lovelace \u003cada@example.com\u003e\nSubject: parser: handle empty input\nPatch 2 of 3 (v1)\n  modified parser.go  +3 -0\n1 files changed, +3 -0\n```\n\n### Walk a patch series from an mbox\n\n```go\nf, _ := os.Open(\"series.mbox\")\ndefer f.Close()\n\ns, err := mailpatch.ParseSeries(f)\nif err != nil {\n\tlog.Fatal(err)\n}\n\nif s.Cover != nil {\n\tfmt.Println(\"cover:\", s.Cover.Subject)\n}\nfmt.Printf(\"v%d, %d/%d patches present (complete=%v)\\n\",\n\ts.Version, s.Len(), s.Total, s.Complete())\n\nfor _, p := range s.Patches { // already sorted by index\n\tfmt.Printf(\"  [%d/%d] %s\\n\", p.Series.Index, p.Series.Total, p.Subject)\n}\n```\n\n### Parse a bare diff (no email)\n\n```go\nfiles, _ := mailpatch.ParseDiff(diffText)\nfor _, f := range files {\n\tfor _, h := range f.Hunks {\n\t\tfor _, ln := range h.Lines {\n\t\t\tswitch ln.Kind {\n\t\t\tcase mailpatch.Add:\n\t\t\t\tfmt.Println(\"+\", ln.Text)\n\t\t\tcase mailpatch.Delete:\n\t\t\t\tfmt.Println(\"-\", ln.Text)\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n## What you get\n\n| Type | Holds |\n|------|-------|\n| `Patch` | From / author name+email, Date, clean Subject, Message-ID / In-Reply-To / References, `SeriesInfo`, commit-message Body, raw Diff, parsed Files, DiffStat |\n| `SeriesInfo` | Index, Total, Version, Prefix, IsCover |\n| `FileChange` | OldPath / NewPath, Type, IsBinary, Old/NewMode, Additions / Deletions, Hunks |\n| `Hunk` | OldStart/OldLines, NewStart/NewLines, Section, Lines |\n| `Line` | Kind (Context / Add / Delete), Text |\n| `DiffStat` | FilesChanged, Additions, Deletions |\n| `Series` | Cover, ordered Patches, Version, Total |\n\n## What this is not\n\n- **Not a patch applier.** It never runs `git am` and never touches your working tree. Parse here, apply (and validate) yourself.\n- **Not a diff renderer.** It gives you the structure; coloring/printing is the caller's job.\n- **Not a full RFC 5322 MTA.** It handles the headers and encodings that format-patch mail uses in practice, not every corner of email.\n\n## Documentation\n\nFull API reference: [pkg.go.dev/github.com/floatpane/go-mailpatch](https://pkg.go.dev/github.com/floatpane/go-mailpatch)\n\nGuides and diagrams: see [`docs/`](docs/).\n\n## Sister projects\n\n| Project | Role |\n|---------|------|\n| [floatpane/matcha](https://github.com/floatpane/matcha) | Reference consumer — uses this library for patch review and `git-mail`. |\n| [floatpane/go-secretbox](https://github.com/floatpane/go-secretbox) | Sibling extraction — password-based encryption for data at rest. |\n\n## Contributing\n\nPRs welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Security\n\nIt parses untrusted list mail. Report vulnerabilities privately via [SECURITY.md](SECURITY.md).\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatpane%2Fgo-mailpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatpane%2Fgo-mailpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatpane%2Fgo-mailpatch/lists"}