Switch to unified view

a b/src/bincimapmime/address.cc
1
/* -*- Mode: c++; -*- */
2
/*  --------------------------------------------------------------------
3
 *  Filename:
4
 *    address.cc
5
 *  
6
 *  Description:
7
 *    Implementation of the Address class.
8
 *  --------------------------------------------------------------------
9
 *  Copyright 2002-2004 Andreas Aardal Hanssen
10
 *
11
 *  This program is free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
24
 *  --------------------------------------------------------------------
25
 */
26
#ifdef HAVE_CONFIG_H
27
#include <config.h>
28
#endif
29
30
#include "address.h"
31
#include "convert.h"
32
#include <string>
33
34
using namespace ::std;
35
using namespace Binc;
36
37
//------------------------------------------------------------------------
38
Address::Address(const string &name, const string &addr)
39
{
40
  string::size_type pos = addr.find('@');
41
  this->name = name;
42
  if (pos != string::npos) {
43
    this->local = addr.substr(0, pos);
44
    this->host = addr.substr(pos + 1);
45
  } else this->local = addr;
46
}
47
48
//------------------------------------------------------------------------
49
Address::Address(const string &wholeaddress)
50
{
51
  string::size_type start = wholeaddress.find('<');
52
  string addr;
53
  if (start != string::npos)
54
    addr = wholeaddress.substr(start + 1);
55
  else
56
    addr = wholeaddress;
57
58
  trim(addr, "<>");
59
60
  if (start != string::npos)
61
    name = wholeaddress.substr(0, start);
62
  else
63
    name = "";
64
  trim(name);
65
  trim(name, "\"");
66
67
  start = addr.find('@');
68
  local = addr.substr(0, start);
69
  host = addr.substr(start + 1);
70
71
  trim(local);
72
  trim(host);
73
  trim(name);
74
}
75
76
//------------------------------------------------------------------------
77
string Address::toParenList(void) const
78
{
79
  string tmp = "(";
80
  tmp += name == "" ? "NIL" : toImapString(name);
81
  tmp += " NIL ";
82
  tmp += local == "" ? "\"\"" : toImapString(local);
83
  tmp += " ";
84
  tmp += host == "" ? "\"\"" : toImapString(host);
85
  tmp += ")";
86
87
  return tmp;
88
}