Skip to content

Commit

Permalink
Parse address lists per RFC 5322.
Browse files Browse the repository at this point in the history
Previously we just split address lists at ", " and hope for the best.
Now we try to parse address lists into a structure and work with that,
e.g. writing out message headers.  Addresses with valid or invalid
syntax are highlighted on the compose screen.
  • Loading branch information
wangp committed Apr 5, 2014
1 parent 256f1e4 commit c8dc839
Show file tree
Hide file tree
Showing 12 changed files with 2,442 additions and 260 deletions.
34 changes: 12 additions & 22 deletions addressbook.m
Expand Up @@ -5,14 +5,16 @@
:- interface.

:- import_module io.
:- import_module maybe.

:- import_module screen.

%-----------------------------------------------------------------------------%

:- func addressbook_section = string.

:- pred expand_aliases(string::in, string::out, io::di, io::uo) is det.
:- pred search_addressbook(string::in, maybe(string)::out, io::di, io::uo)
is det.

:- pred prompt_addressbook_add(screen::in, string::in, io::di, io::uo)
is det.
Expand All @@ -25,7 +27,6 @@
:- import_module char.
:- import_module int.
:- import_module list.
:- import_module maybe.
:- import_module string.

:- import_module callout.
Expand All @@ -48,30 +49,19 @@

%-----------------------------------------------------------------------------%

expand_aliases(String0, String, !IO) :-
Words0 = string.split_at_string(", ", String0),
list.map_foldl(expand_aliases_2, Words0, Words1, !IO),
( Words0 = Words1 ->
String = String0
;
String = string.join_list(", ", Words1)
).

:- pred expand_aliases_2(string::in, string::out, io::di, io::uo) is det.

expand_aliases_2(Word0, Expansion, !IO) :-
Word1 = string.strip(Word0),
( string.all_match(is_alias_char, Word1) ->
Key = addressbook_section ++ "." ++ Word1,
get_notmuch_config(Key, MaybeValue, !IO),
search_addressbook(Alias, MaybeFound, !IO) :-
( string.all_match(is_alias_char, Alias) ->
Key = addressbook_section ++ "." ++ Alias,
get_notmuch_config(Key, Res, !IO),
(
MaybeValue = ok(Expansion)
Res = ok(Expansion),
MaybeFound = yes(Expansion)
;
MaybeValue = error(_),
Expansion = Word0
Res = error(_),
MaybeFound = no
)
;
Expansion = Word0
MaybeFound = no
).

%-----------------------------------------------------------------------------%
Expand Down

0 comments on commit c8dc839

Please sign in to comment.