/** * @file address.cc * @brief Implementation of the Address class * @author Andreas Aardal Hanssen * @date 2005 */ #include "address.h" #include "convert.h" #include using namespace Binc; using std::string; using std::string_view; Address Address::from(string name, string_view addr) { if (auto pos = addr.find('@'); pos != string::npos) return Address{std::move(name), string{addr.substr(0, pos)}, string{addr.substr(pos + 1)}}; else return Address{std::move(name), string{addr}}; } Address Address::from(string_view wholeaddress) { auto start = wholeaddress.find('<'); auto addr = start != string::npos ? wholeaddress.substr(start + 1) : wholeaddress; auto name = start != string::npos ? wholeaddress.substr(0, start) : ""; trim(addr, "<>"); trim(name); trim(name, "\""); start = addr.find('@'); auto local = addr.substr(0, start); auto host = addr.substr(start + 1); trim(local); trim(host); return Address{string{name}, string{local}, string{host}}; } string Address::toParenList() const { string tmp = "("; tmp += name == "" ? "NIL" : toImapString(name); tmp += " NIL "; tmp += local == "" ? "\"\"" : toImapString(local); tmp += " "; tmp += host == "" ? "\"\"" : toImapString(host); tmp += ")"; return tmp; }