Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
RecordMail.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file RecordMAIL.cpp 00004 * @author ST / Central Labs 00005 * @version V2.0.0 00006 * @date 28 Apr 2017 00007 * @brief RecordMail implementation. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 #include "RecordMail.h" 00038 00039 namespace NDefLib { 00040 00041 const std::string RecordMail::sSubjectTag("?subject="); 00042 const std::string RecordMail::sBodyTag("&body="); 00043 00044 void RecordMail::update_content(){ 00045 if (!mContentIsChange) { 00046 return; 00047 } 00048 00049 mContent.reserve(mToAddress.size() + sSubjectTag.size() + mSubject.size() + sBodyTag.size() + mBody.size()); 00050 mContent = mToAddress; 00051 mContent += sSubjectTag; 00052 mContent += mSubject; 00053 mContent += sBodyTag; 00054 mContent += mBody; 00055 00056 mContentIsChange=false; 00057 } 00058 00059 RecordMail* RecordMail::parse(const RecordHeader &header, const uint8_t* buffer) { 00060 //not a uri tag or a mail tag 00061 if (buffer[0] != RecordURI::sNDEFUriIdCode || buffer[1] != RecordURI::MAIL) { 00062 return NULL; 00063 } 00064 const std::string uriContent((const char*) (buffer + 2), header.get_payload_length() - 1); 00065 00066 std::size_t subjectStart = uriContent.find(sSubjectTag); 00067 if (subjectStart == std::string::npos) { //subject not present 00068 return NULL; 00069 } 00070 const std::size_t destSize = subjectStart; 00071 subjectStart += sSubjectTag.size(); //skip the tag string 00072 00073 std::size_t bodyStart = uriContent.find(sBodyTag); 00074 if (bodyStart == std::string::npos) { //body not present 00075 return NULL; 00076 } 00077 const std::size_t subjectLenght = bodyStart - subjectStart; 00078 bodyStart += sBodyTag.size(); // skip the tag string 00079 00080 const std::size_t bodyLenght = uriContent.size() - bodyStart; 00081 00082 return new RecordMail(uriContent.substr(0, destSize), 00083 uriContent.substr(subjectStart, subjectLenght), 00084 uriContent.substr(bodyStart, bodyLenght)); 00085 00086 } 00087 00088 } /* namespace NDefLib */ 00089 00090 00091 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 14:14:48 by
1.7.2
