Skip to content

Commit

Permalink
Merge pull request #56 from mirage/better-unstrctrd-encoding
Browse files Browse the repository at this point in the history
Add a space in front of any field's values
  • Loading branch information
dinosaure authored May 20, 2021
2 parents b154c03 + 329ffad commit e7b3ac8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
25 changes: 18 additions & 7 deletions lib/field.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,22 @@ module Encoder = struct

let field ppf field =
let (Field (field_name, w, v)) = field in
let e = encoder w in
eval ppf
[
tbox 1; !!Field_name.Encoder.field_name; string $ ":"; spaces 1; !!e;
close; new_line;
]
field_name v
match w with
| Unstructured ->
let e = encoder w in
let separator = match v with `WSP _ :: _ -> ":" | _ -> ": " in
eval ppf
[
tbox 1; !!Field_name.Encoder.field_name; !!string; !!e; close;
new_line;
]
field_name separator v
| w ->
let e = encoder w in
eval ppf
[
tbox 1; !!Field_name.Encoder.field_name; string $ ": "; !!e; close;
new_line;
]
field_name v
end
7 changes: 5 additions & 2 deletions test/test_mail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let test1 () =
| Error _ -> Fmt.invalid_arg "Generate unparsable email"

let subject =
"Something larger than 80 columns to see where prettym split contents.A \
"Something larger than 80 columns to see where prettym split contents. A \
large Subject should be split!"

let example2 =
Expand All @@ -225,7 +225,10 @@ let to_unstrctrd unstrctrd =
| Error (`Msg err) -> failwith err

let remove_fws (unstrctrd : Unstrctrd.t) =
let fold acc = function `FWS _ -> acc | x -> x :: acc in
let fold acc = function
| `FWS _ -> Unstrctrd.wsp ~len:1 :: acc
| x -> x :: acc
in
match
List.fold_left fold [] (unstrctrd :> Unstrctrd.elt list)
|> List.rev
Expand Down

0 comments on commit e7b3ac8

Please sign in to comment.