2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
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, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module addrbook
/*is aliced*/;
27 // ////////////////////////////////////////////////////////////////////////// //
28 public final class AddressBookEntry
{
30 dynstring realname
; // can be empty
31 dynstring mail
; // email
35 public __gshared AddressBookEntry
[] abook
;
38 // ////////////////////////////////////////////////////////////////////////// //
39 public AddressBookEntry
abookFindByNickFirst (const(char)[] nick
) {
41 if (nick
.length
== 0) return null;
43 foreach (AddressBookEntry ae
; abook
) {
44 if (ae
.nick
.strEquCI(nick
)) return ae
;
47 foreach (AddressBookEntry ae
; abook
) {
48 if (ae
.nick
.startsWithCI(nick
)) return ae
;
55 public AddressBookEntry
abookFindByNick (const(char)[] nick
) {
57 if (nick
.length
== 0) return null;
59 foreach (AddressBookEntry ae
; abook
) {
60 if (ae
.nick
.strEquCI(nick
)) return ae
;
63 AddressBookEntry partial
;
64 foreach (AddressBookEntry ae
; abook
) {
65 if (ae
.nick
.startsWithCI(nick
)) {
66 if (partial
!is null) return null;
74 // ////////////////////////////////////////////////////////////////////////// //
75 public AddressBookEntry
abookFindByMailFirst (const(char)[] mail
) {
77 if (mail
.length
== 0) return null;
79 foreach (AddressBookEntry ae
; abook
) {
80 if (ae
.mail
.strEquCI(mail
)) return ae
;
83 foreach (AddressBookEntry ae
; abook
) {
84 if (ae
.mail
.startsWithCI(mail
)) return ae
;
91 public AddressBookEntry
abookFindByMail (const(char)[] mail
) {
93 if (mail
.length
== 0) return null;
95 foreach (AddressBookEntry ae
; abook
) {
96 if (ae
.mail
.strEquCI(mail
)) return ae
;
99 AddressBookEntry partial
;
100 foreach (AddressBookEntry ae
; abook
) {
101 if (ae
.mail
.startsWithCI(mail
)) {
102 if (partial
!is null) return null;
110 // ////////////////////////////////////////////////////////////////////////// //
111 shared static this () {
112 //addressbook_add nick noip name "Ketmar Dark" email "ketmar@ketmar.no-ip.org"
113 conRegFunc
!((ConString nick
, ConString
[] args
) {
115 if (nick
.length
== 0) { conwriteln("addressbook_add: empty nick"); return; }
116 auto origargs
= args
;
117 auto ae
= new AddressBookEntry();
119 while (args
.length
) {
120 if (args
.length
< 2) { conwriteln("addressbook_add: invalid args: ", origargs
); return; }
127 if (ae
.mail
.length
!= 0) {
128 conwriteln("addressbook_add: duplicate mail option: '", arg
, "'");
129 conwriteln("addressbook_add: invalid args: ", origargs
);
137 if (ae
.realname
.length
!= 0) {
138 conwriteln("addressbook_add: duplicate name option: '", arg
, "'");
139 conwriteln("addressbook_add: invalid args: ", origargs
);
142 ae
.realname
= arg
.idup
;
145 conwriteln("addressbook_add: unknown options: '", opt
, "'");
146 conwriteln("addressbook_add: invalid args: ", origargs
);
150 if (ae
.mail
.length
== 0) { conwriteln("addressbook_add: invalid args (no mail): ", origargs
); return; }
151 foreach (ref AddressBookEntry oae
; abook
) {
152 if (oae
.nick
.strEquCI(nick
)) { oae
= ae
; return; }
155 })("addressbook_add", "add address book entry");