{"id":13507844,"url":"https://github.com/kbrw/mailibex","last_synced_at":"2025-05-07T21:41:13.452Z","repository":{"id":22390089,"uuid":"25726976","full_name":"kbrw/mailibex","owner":"kbrw","description":"Library containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp","archived":false,"fork":false,"pushed_at":"2024-03-12T09:49:30.000Z","size":1398,"stargazers_count":62,"open_issues_count":7,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-17T02:31:43.106Z","etag":null,"topics":["decoding","dkim","dmarc","elixir","mimemail","smtp","spf"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/kbrw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2014-10-25T09:53:02.000Z","updated_at":"2024-11-03T15:32:49.000Z","dependencies_parsed_at":"2024-05-01T16:19:46.940Z","dependency_job_id":"8410534e-85a8-4615-b019-7cb579ec3503","html_url":"https://github.com/kbrw/mailibex","commit_stats":null,"previous_names":["awetzel/mailibex"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fmailibex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fmailibex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fmailibex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbrw%2Fmailibex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kbrw","download_url":"https://codeload.github.com/kbrw/mailibex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252961430,"owners_count":21832184,"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","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":["decoding","dkim","dmarc","elixir","mimemail","smtp","spf"],"created_at":"2024-08-01T02:00:40.811Z","updated_at":"2025-05-07T21:41:13.427Z","avatar_url":"https://github.com/kbrw.png","language":"Elixir","funding_links":[],"categories":["Email"],"sub_categories":[],"readme":"mailibex [![Build Status](https://travis-ci.org/kbrw/mailibex.svg?branch=master)](https://travis-ci.org/kbrw/mailibex) \n========\n\nLibrary containing Email related implementations in Elixir : dkim, spf, dmark, mimemail, smtp\n\n## MimeMail ##\n\n```elixir\n%MimeMail{headers: [{key::atom, {:raw,binary} | MimeMail.Header.t}], body: binary | [MimeMail.t] | {:raw,binary}}\n# headers contains a keywordlist of either the raw form of the header, \n# or an encodable version of the header (a term with a module implementing MimeMail.Header.to_ascii)\n# body contains either the raw binary body, the decoded body as a binary (using content-transfer-encoding), \n# or a list of MimeMail struct to encode in case of a multipart\n# If body is a text, then the decoded body binary will be the UTF8 version of the text converted from the source charset\n```\n\n- `MimeMail.from_string` parse the mimemail binary into a `MimeMail` struct explained above, with all the headers and body in their encoded form (`{:raw,binary}`)\n- `MimeMail.encode_headers(mail)` apply the `MimeMail.Header.to_ascii` to every header to convert them into a `{:raw,binary}` form.\n- `MimeMail.decode_headers(mail,[Mod1,Mod2])` applies successively `Mod1.decode_headers(mail)` the `Mod2.decode_headers(mail)` to the result.\n- `MimeMail.encode_body(mail)` encodes the mail body from a decoded form (`binary | [MimeMail]`) into a `{:raw,binary}`form\n- `MimeMail.decode_body(mail)` does the opposite.\n- `MimeMail.to_string(mail)` encode headers and body of a `MimeMail` into an ascii mail binary.\n\nCurrently, the library contains three types of acceptable header value (implementing `MimeMail.Header`) :\n- `binary` : simple binary headers are utf8 strings converted into encoded words\n- `{value,%{}=params}` are only acceptable tuple as header, converted into a 'content-*' style header ( `value; param1=value1, param2=value2`)\n- `[%MimeMail.Address{name=\"toto\", address: \"toto@example.org\"}]` : lists are encoded into mailbox list header\n- `%DKIM{}` : Converted into a dkim header\n\nSo for instance : \n```elixir\n%MimeMail{headers: [\n    to: [%MimeMail.Address{name: \"You\",address: \"you@m.org\"}],\n    from: [%MimeMail.Address{name: \"Me\",address: \"me@m.org\"}],\n    cc: \"me@m.org\", # only ascii so ok to encode it as a simple encoded word\n    'content-type': {'text/plain',%{charset: \"utf8\"}},\n  ],\n  body: \"Hello world\"}\n|\u003e MimeMail.to_string\n```\n\n## FlatMail ##\n\nFlat mail representation of MimeMail is simply a `KeywordList` where\nall the keys `[:txt,:html,:attach,:attach_in,:include]` are used to construct the body tree of \nalternative/mixed/related multiparts in the `body` field of the\n`MimeMail` struct, and the rest of the `KeywordList` became the\n`header` field.\n\n```elixir\nMimeMail.Flat.to_mail(from: \"me@example.org\", txt: \"Hello world\", attach: \"attached plain text\", attach: File.read!(\"attachedfile\"))\n|\u003e MimeMail.to_string\n```\n\nNeed more explanations here...\n\n## MimeTypes ##\n\n`ext2mime` and `mime2ext` are functions generated at compilation time from the apache mime configuration file https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types .\n\n```elixir\n\"image/png\" = MimeTypes.ext2mime(\".png\")\n\".png\" = MimeTypes.mime2ext(\"image/png\")\n```\n\n`bin2ext` matches the begining of the binary and sometimes decode the binary in order to determine the file extension (then we can use `ext2mime`to find the mime type if needed.\n\n```elixir\n\".webm\" = MimeTypes.bin2ext(File.read!(\"path/to/my/webm/file.webm\"))\n```\n\n## DKIM ##\n\n```elixir\n[rsaentry] =  :public_key.pem_decode(File.read!(\"test/mails/key.pem\"))\nmail = MimeMail.from_string(data)\n\nmail = DKIM.sign(mail,:public_key.pem_entry_decode(rsaentry), d: \"order.brendy.fr\", s: \"cobrason\")\ncase DKIM.check(mail) do\n  :none      -\u003eIO.puts(\"no dkim signature\")\n  {:pass,{key,org}}      -\u003eIO.puts(\"the mail is signed by #{key} at #{org}\")\n  :tempfail  -\u003e IO.puts(\"the dns record is unavailable, try later\")\n  {:permfail,msg}-\u003eIO.puts(\"the sender is not authorized because #{msg}\")\nend\n```\n\nNeed more explanations here...\n\n## DMARC ##\n\nOrganizational Domain implementation using public suffix database : \n(https://publicsuffix.org/list/effective_tld_names.dat)\n\n```elixir\n\"orga2.gouv.fr\" = DMARK.organization \"orga0.orga1.orga2.gouv.fr\"\n```\n\n## SPF ##\n\nFull implementation of the Sender Policy Framework (https://tools.ietf.org/html/rfc7208).\n\n```elixir\ncase SPF.check(\"me@example.org\",{1,2,3,4}, helo: \"relay.com\", server_domain: \"me.com\") do\n  :none      -\u003eIO.puts(\"no SPF information\")\n  :neutral   -\u003eIO.puts(\"nor authorized neither not authorized\")\n  :pass      -\u003eIO.puts(\"the sender is authorized\")\n  {:fail,msg}-\u003eIO.puts(\"the sender is not authorized because #{msg}\")\n  :softfail  -\u003eIO.puts(\"not authorized but don't be rude\")\n  :temperror -\u003eIO.puts(\"temporary error, try again latter\")\n  :permerror -\u003eIO.puts(\"spf error, ask to remote admin\")\nend\n```\n\n## Current Status\n\n- DKIM is fully implemented (signature/check), missing DKIM-Quoted-Printable token management\n- mimemail encoding/decoding of headers and body are fully implemented\n- flat mime body representation for easy mail creation / modification\n- DMARC implementation of organizational domains\n- SPF is fully implemented\n\n## TODO :\n\n- DMARC report\n- smtp client implementation\n- smtp server implementation over Ranch\n\n# CONTRIBUTING\n\nHi, and thank you for wanting to contribute.\nPlease refer to the centralized informations available at: https://github.com/kbrw#contributing\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbrw%2Fmailibex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkbrw%2Fmailibex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbrw%2Fmailibex/lists"}