Skip to content

Commit

Permalink
Merge pull request #34 from oxidizing/feature/upgrade_to_colombe_0.4.0
Browse files Browse the repository at this point in the history
Feature/upgrade to colombe 0.4.0
  • Loading branch information
aronerben authored Dec 4, 2020
2 parents 02984eb + 4140901 commit ac189a2
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 118 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
fail-fast: false
matrix:
os:
- macos-latest
# Disable macos build for now since it keeps failing with dune not found
# - macos-latest
- ubuntu-latest
ocaml-version:
- 4.11.1
Expand All @@ -36,6 +37,7 @@ jobs:
- name: Install dependencies
if: steps.cache-opam.outputs.cache-hit != 'true'
run: |
opam install -y dune
opam install -y . --deps-only --with-doc --with-test --locked --unlock-base
- name: Recover from an Opam broken state
if: steps.cache-opam.outputs.cache-hit == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/_build/
/_opam/
.merlin
ethereal_account.json
*_account.json
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,50 @@ These tests are still somewhat far from good and you need to validate all result

#### Service tests

These tests are somewhat slow and fragile and because of that these are expected to be run manually.
Because these tests are somewhat slow and fragile, you need to run them manually. Execution of these tests depends on test accounts on *ethereal.email* and *mailtrap.io*. Before execution, you need to create configuration files with authentication credentials for each service. You can generate these configuration files by using the shell command snippets given below, but for those you need to have `jq` application installed. If you don't have it or you don't want to install it, you can also create `ethereal_account.json` and `mailtrap_account.json` files manually. Both files have the following format:

``` json-with-comments
{
"host": "smtp.ethereal.email or smtp.mailtrap.io",
"port": 587,
"username": "username for SMTP authentication",
"password": "password for SMTP authentication",
"secure": false // we will always use encryption, but `false` causes use of STARTTLS
}
```

First create *ethereal.email* account and store account details
To create temporary *ethereal.email* account and store the account details, you can execute the following one-liner:

``` shell
curl -d '{ "requestor": "letters", "version": "dev" }' "https://api.nodemailer.com/user" -X POST -H "Content-Type: application/json" > ethereal_account.json
curl -s -d '{ "requestor": "letters", "version": "dev" }' "https://api.nodemailer.com/user" -X POST -H "Content-Type: application/json" | jq '{ hostname: .smtp.host, port: .smtp.port, secure: false, username: .user, password: .pass, }'> ethereal_account.json
```

Currently using `ethereal.email` service requires non-released version of `colombe` and
you need to check out the project, commit `edf757c58fce58c170c63e8a92d3bc81fe4d32ff` contains the needed fix. Then the version with the fix needs to be pinned in the build env:
For *mailtrap.io*, you need to create a personal account first and get the API key:
- [signup](https://mailtrap.io/register/signup?ref=header)
- [copy API token from Settings](https://mailtrap.io/settings)

The configuration file you can create with following steps:
- create environment variable containing your API token: `export MAILTRAP_API_TOKEN=<API token>`
- run the following one-liner in terminal to create the configuration file:

``` shell
# Move to folder where colombe is checked out
pushd /path/to/colombe
# Switch to correct git commit in colombe repo
git switch --detach edf757c58fce58c170c63e8a92d3bc81fe4d32ff
# Switch to use same opam env that is used by letters
eval "$(opam env --switch $(dirs | cut -d ' ' -f 2) --set-switch)"
# Pin this specific version of colombe (and all related packages)
opam pin .
# Finally, return back to letters project
popd
curl -s -H "Authorization: Bearer ${MAILTRAP_API_TOKEN}" "https://mailtrap.io/api/v1/inboxes" | jq '.[0] | { hostname: .domain, port: .smtp_ports[2], secure: false, username: .username, password: .password }' > mailtrap_account.json
```

Then execute these tests (actually this runs all tests):
Now you are ready to execute these tests. You can run them with the following command:

``` shell
dune build @runtest-all
```

And finally review that the email is correctly generated in the service:
Finally review that all emails are correctly received in *ethreal.email*:
- login to https://ethereal.email/login using credentials from the `ethereal_account.json`
- check the content of messages: https://ethereal.email/messages
- check the content of new messages: https://ethereal.email/messages

Also check that you can find all emails in the inbox in *mailtrap.io*:
- login to [mailtrap.io](https://mailtrap.io/signin) using your personal credentials
- select the first inbox (unless you use another one), from [inboxes](https://mailtrap.io/inboxes)
- check the content of new messages

## Credits

Expand Down
5 changes: 2 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
(depends
(ocaml (>= 4.08.1))
(dune (>= 2.3))
(emile (>= 1.0))
(mrmime (>= 0.3.1))
(colombe (>= 0.3.0))
(sendmail-lwt (>= 0.3.0))
(colombe (>= 0.4.0))
(sendmail (>= 0.4.0))
(fmt (>= 0.8.8))
(x509 (>= 0.9.0))
(ptime (>= 0.8.5))
Expand Down
5 changes: 2 additions & 3 deletions letters.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ bug-reports: "https://github.com/oxidizing/letters/issues"
depends: [
"ocaml" {>= "4.08.1"}
"dune" {>= "2.3"}
"emile" {>= "1.0"}
"mrmime" {>= "0.3.1"}
"colombe" {>= "0.3.0"}
"sendmail-lwt" {>= "0.3.0"}
"colombe" {>= "0.4.0"}
"sendmail" {>= "0.4.0"}
"fmt" {>= "0.8.8"}
"x509" {>= "0.9.0"}
"ptime" {>= "0.8.5"}
Expand Down
43 changes: 21 additions & 22 deletions letters.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doc: "https://oxidizing.github.io/letters/"
bug-reports: "https://github.com/oxidizing/letters/issues"
depends: [
"angstrom" {= "0.15.0"}
"asn1-combinators" {= "0.2.3"}
"asn1-combinators" {= "0.2.4"}
"astring" {= "0.8.5"}
"base" {= "v0.14.0"}
"base-bytes" {= "base"}
Expand All @@ -19,10 +19,10 @@ depends: [
"base64" {= "3.4.0"}
"bigarray-compat" {= "1.0.0"}
"bigarray-overlap" {= "0.2.0"}
"bigstringaf" {= "0.6.1"}
"bigstringaf" {= "0.7.0"}
"cmdliner" {= "1.0.4"}
"coin" {= "0.1.3"}
"colombe" {= "0.3.0"}
"colombe" {= "0.4.0"}
"conf-gmp" {= "2"}
"conf-gmp-powm-sec" {= "2"}
"conf-m4" {= "1"}
Expand All @@ -36,66 +36,65 @@ depends: [
"dune" {= "2.7.1"}
"dune-configurator" {= "2.7.1"}
"duration" {= "0.1.3"}
"emile" {= "1.0"}
"emile" {= "1.1"}
"eqaf" {= "0.7"}
"fiat-p256" {= "0.2.1"}
"fiat-p256" {= "0.2.3"}
"fmt" {= "0.8.9"}
"fpath" {= "0.7.3"}
"gmap" {= "0.3.0"}
"hacl_x25519" {= "0.2.0"}
"hacl_x25519" {= "0.2.2"}
"hex" {= "1.4.0"}
"hkdf" {= "1.0.4"}
"ipaddr" {= "5.0.1"}
"ke" {= "0.4"}
"logs" {= "0.7.0"}
"lwt" {= "5.3.0"}
"macaddr" {= "5.0.1"}
"menhir" {= "20200624"}
"menhirLib" {= "20200624"}
"menhirSdk" {= "20200624"}
"mirage-crypto" {= "0.8.5"}
"mirage-crypto-pk" {= "0.8.5"}
"mirage-crypto-rng" {= "0.8.5"}
"menhir" {= "20201201"}
"menhirLib" {= "20201201"}
"menhirSdk" {= "20201201"}
"mirage-crypto" {= "0.8.7"}
"mirage-crypto-pk" {= "0.8.7"}
"mirage-crypto-rng" {= "0.8.7"}
"mirage-no-solo5" {= "1"}
"mirage-no-xen" {= "1"}
"mmap" {= "1.1.0"}
"mrmime" {= "0.3.1"}
"mrmime" {= "0.3.2"}
"mtime" {= "1.2.0"}
"num" {= "1.3"}
"num" {= "1.4"}
"ocaml" {= "4.08.1"}
"ocaml-compiler-libs" {= "v0.12.3"}
"ocaml-config" {= "1"}
"ocaml-migrate-parsetree" {= "2.0.0"}
"ocaml-migrate-parsetree" {= "2.1.0"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocamlbuild" {= "0.14.0"}
"ocamlfind" {= "1.8.1"}
"ocplib-endian" {= "1.1"}
"parsexp" {= "v0.14.0"}
"pecu" {= "0.4"}
"pecu" {= "0.5"}
"ppx_cstruct" {= "6.0.0"}
"ppx_derivers" {= "1.2.1"}
"ppx_sexp_conv" {= "v0.14.1"}
"ppxlib" {= "0.17.0"}
"ppx_sexp_conv" {= "v0.14.2"}
"ppxlib" {= "0.20.0"}
"ptime" {= "0.8.5"}
"re" {= "1.9.0"}
"result" {= "1.5"}
"rosetta" {= "0.3.0"}
"rresult" {= "0.6.0"}
"sendmail" {= "0.3.0"}
"sendmail-lwt" {= "0.3.0"}
"sendmail" {= "0.4.0"}
"seq" {= "base"}
"sexplib" {= "v0.14.0"}
"sexplib0" {= "v0.14.0"}
"stdlib-shims" {= "0.1.0"}
"tls" {= "0.12.5"}
"tls" {= "0.12.6"}
"topkg" {= "1.0.3"}
"uchar" {= "0.0.2"}
"unstrctrd" {= "0.2"}
"uutf" {= "1.0.2"}
"uuuu" {= "0.2.0"}
"x509" {= "0.11.2"}
"yuscii" {= "0.3.0"}
"zarith" {= "1.10"}
"zarith" {= "1.11"}
]
build: [
["dune" "subst"] {pinned}
Expand Down
16 changes: 14 additions & 2 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
(library
(name letters)
(public_name letters)
(libraries mrmime ptime.clock.os lwt fpath colombe colombe.emile
sendmail-lwt sendmail.tls))
(libraries
ptime.clock.os
lwt
lwt.unix
tls
tls.lwt
fpath
colombe
colombe.emile
mrmime
sendmail
sendmail.starttls
)
)
5 changes: 3 additions & 2 deletions lib/letters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let send ~config:c ~sender ~recipients ~message =
let from_mailbox =
match Emile.of_string sender with
| Ok v -> v
| Error (`Invalid (_,_)) -> failwith "Invalid sender address"
| Error (`Invalid (_, _)) -> failwith "Invalid sender address"
in
let from_addr =
match Colombe_emile.to_reverse_path from_mailbox with
Expand Down Expand Up @@ -248,7 +248,8 @@ let send ~config:c ~sender ~recipients ~message =
match res with
| Ok () -> Lwt.return ()
| Error err ->
Lwt.fail_with (Fmt.str "Sending email failed, %a" Sendmail_with_tls.pp_error err)
Lwt.fail_with
(Fmt.str "Sending email failed, %a" Sendmail_with_starttls.pp_error err)
else
let* res =
Sendmail_handler.run
Expand Down
4 changes: 2 additions & 2 deletions lib/sendmail_handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let run_with_starttls
| None -> 465
in
let tls = Tls.Config.client ~authenticator:tls_authenticator () in
let ctx = Sendmail_with_tls.Context_with_tls.make () in
let ctx = Sendmail_with_starttls.Context_with_tls.make () in
let open Lwt.Infix in
Lwt_unix.gethostbyname (Domain_name.to_string hostname)
>>= fun res ->
Expand All @@ -71,7 +71,7 @@ let run_with_starttls
| None -> Lwt_scheduler.inj (Lwt.return None)
in
let fiber =
Sendmail_with_tls.sendmail
Sendmail_with_starttls.sendmail
lwt
rdwr
{ ic; oc }
Expand Down
2 changes: 1 addition & 1 deletion lib/sendmail_handler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val run_with_starttls
-> from:Colombe.Reverse_path.t
-> recipients:Colombe.Forward_path.t list
-> mail:Mrmime.Mt.buffer Mrmime.Mt.stream
-> (unit, Sendmail_with_tls.error) Lwt_result.t
-> (unit, Sendmail_with_starttls.error) Lwt_result.t

val run
: hostname:'a Domain_name.t
Expand Down
Loading

0 comments on commit ac189a2

Please sign in to comment.