1 //
2 //      aegis - project change supervisor
3 //      Copyright (C) 2004-2008, 2012 Peter Miller
4 //
5 //      This program is free software; you can redistribute it and/or modify
6 //      it under the terms of the GNU General Public License as published by
7 //      the Free Software Foundation; either version 3 of the License, or
8 //      (at your option) any later version.
9 //
10 //      This program is distributed in the hope that it will be useful,
11 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //      GNU General Public License for more details.
14 //
15 //      You should have received a copy of the GNU General Public License
16 //      along with this program. If not, see
17 //      <http://www.gnu.org/licenses/>.
18 //
19 
20 #include <common/arglex.h>
21 #include <common/nstring/list.h>
22 #include <common/trace.h>
23 #include <common/wstring/list.h>
24 #include <libaegis/sub.h>
25 #include <libaegis/sub/email_addres.h>
26 #include <libaegis/user.h>
27 
28 
29 wstring
sub_email_address(sub_context_ty *,const wstring_list & arg)30 sub_email_address(sub_context_ty *, const wstring_list &arg)
31 {
32     trace(("sub_email_address()\n{\n"));
33     nstring_list words;
34     bool quote = false;
35     const char *separator = 0;
36     size_t j = 1;
37     for (; j < arg.size(); ++j)
38     {
39         nstring option = arg[j].to_nstring();
40         if (arglex_compare("-Comma", option.c_str(), 0))
41             separator = ", ";
42         else if (arglex_compare("-Quote", option.c_str(), 0))
43             quote = true;
44         else
45             break;
46     }
47     for (; j < arg.size(); ++j)
48     {
49         nstring login = arg[j].to_nstring();
50         user_ty::pointer up = user_ty::create(login);
51         nstring s = up->get_email_address();
52         if (quote)
53             s = s.quote_shell();
54         words.push_back_unique(s);
55     }
56 
57     //
58     // Convert the work list to a single string.
59     //
60     nstring rs = words.unsplit(separator);
61     wstring result(rs);
62 
63     //
64     // all done
65     //
66     trace(("return %p;\n", result.get_ref()));
67     trace(("}\n"));
68     return result;
69 }
70 
71 
72 // vim: set ts=8 sw=4 et :
73