00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SMTPUtils.h"
00019 #include "debug/Log.h"
00020 #include "util/Regex.h"
00021
00022 namespace oasys {
00023
00024
00025 bool
00026 SMTPUtils::extract_address(const std::string& str, std::string* address)
00027 {
00028
00029 Regex pat("([A-Za-z0-9_]+@[A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)+)", REG_EXTENDED);
00030
00031 int err = pat.match(str.c_str(), 0);
00032 if (err != 0) {
00033 log_debug_p("/oasys/smtp/utils",
00034 "extract_address %s failed: %s",
00035 str.c_str(), pat.regerror_str(err).c_str());
00036 return false;
00037 }
00038
00039 ASSERT(pat.num_matches() >= 1);
00040
00041 address->assign(str.substr(pat.get_match(0).rm_so,
00042 pat.get_match(0).rm_eo - pat.get_match(0).rm_so));
00043
00044 log_debug_p("/oasys/smtp/utils",
00045 "extract_address %s -> %s", str.c_str(), address->c_str());
00046 return true;
00047 }
00048
00049 }