2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 #include <Commons/Exception.h>
21 #include <Commons/StringBuilder.h>
22 #include <Commons/StringUtils.h>
23 #include "EmailUtils.h"
27 using namespace WrtDeviceApis::Commons;
30 const char* EMAIL_ADDRESS_REGEX =
31 "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}";
33 const std::string EMAIL_ADDRESS_REGEX_GROUP =
36 .append(EMAIL_ADDRESS_REGEX)
42 namespace EmailUtils {
43 std::string formatAddress(const std::string& address,
44 const std::string& name)
46 if (address.empty()) {
47 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Address is empty.");
52 ss << "\"" << name << "\" ";
54 ss << "<" << address << ">";
59 std::string formatAddressLine(const Recipients& recipients)
62 for (size_t i = 0; i < recipients.getRecipientSize(); ++i) {
63 result += formatAddress(recipients.getRecipient(i)) + ";";
68 std::string stripAddress(const std::string& address)
71 pcrecpp::RE re(EMAIL_ADDRESS_REGEX_GROUP);
72 if (!re.PartialMatch(address, &result)) {
73 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't discover email address");
78 Recipients stripAddressLine(const std::string& addressLine)
80 typedef std::vector<std::string> Addresses;
83 Addresses addresses = String::split(addressLine, ';');
84 for (Addresses::iterator it = addresses.begin();
85 it != addresses.end();
87 result.appendRecipient(stripAddress(*it));
92 bool isFrameworkEmailData(char* filePath)
94 std::string tempString1;
95 std::string tempString2;
99 LoggerD("filePath is NULL");
103 LoggerD("filePath : " << filePath);
105 tempString1.assign(filePath);
106 tempString2.assign(EMAIL_DATA_FILE_PATH);
108 if(tempString1.size() < tempString2.size())
111 if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
113 LoggerD("email frame work files");
117 LoggerD("tmp files");