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 size_t tempSize = recipients.getRecipientSize();
64 for (size_t i = 0; i < tempSize; ++i) {
67 result += formatAddress(recipients.getRecipient(i)) + ";";
71 result += formatAddress(recipients.getRecipient(i));
77 std::string stripAddress(const std::string& address)
80 pcrecpp::RE re(EMAIL_ADDRESS_REGEX_GROUP);
81 if (!re.PartialMatch(address, &result)) {
82 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't discover email address");
87 Recipients stripAddressLine(const std::string& addressLine)
89 typedef std::vector<std::string> Addresses;
92 Addresses addresses = String::split(addressLine, ';');
93 for (Addresses::iterator it = addresses.begin();
94 it != addresses.end();
96 result.appendRecipient(stripAddress(*it));
101 bool isFrameworkEmailData(char* filePath)
103 std::string tempString1;
104 std::string tempString2;
108 LoggerD("filePath is NULL");
112 LoggerD("filePath : " << filePath);
114 tempString1.assign(filePath);
115 tempString2.assign(EMAIL_DATA_FILE_PATH);
117 if(tempString1.size() < tempString2.size())
120 if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
122 LoggerD("email frame work files");
126 LoggerD("tmp files");