SMTPUtils.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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     // try a simple regex for now
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 } // namespace oasys

Generated on Sat Sep 8 08:43:34 2007 for DTN Reference Implementation by  doxygen 1.5.3