Skip to content

Commit

Permalink
Merge pull request #5 from jeremydumais/SmtpClientRefactoring
Browse files Browse the repository at this point in the history
Smtp client refactoring
  • Loading branch information
jeremydumais authored May 27, 2021
2 parents b3f8019 + 6b45cf6 commit 178c34d
Show file tree
Hide file tree
Showing 20 changed files with 1,384 additions and 1,470 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file

## [1.1.2]

### Updated
- Refactor the code of the SmtpClient class to inherit the SmtpClientBase class.
- You must now call the method getCommunicationLog() instead of getServerReply()

## [1.1.1]

### Added
- Add support for the cc and bcc field in the sendMail method

## [1.1.0]

Expand Down
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=.;-line-filter=[{\"name\":\"src/base64.cpp\",\"lines\":[[1000,1000]]},{\"name\":\".h\"},{\"name\":\".cpp\"}];-checks=*,-llvm-header-guard,-google-build-using-namespace,-fuchsia-default-arguments,-modernize-pass-by-value,-fuchsia-overloaded-operator,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=.;-line-filter=[{\"name\":\"src/base64.cpp\",\"lines\":[[1000,1000]]},{\"name\":\".h\"},{\"name\":\".cpp\"}];-checks=*,-llvm-header-guard,-google-build-using-namespace,-fuchsia-default-arguments,-modernize-pass-by-value,-fuchsia-overloaded-operator,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type")
endif()

set(CMAKE_BUILD_TYPE Debug)

# Set directories
set(PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
set(SRC_PATH "${PROJECT_PATH}/src")
Expand Down Expand Up @@ -84,6 +82,7 @@ set(PROJECT_SOURCE_FILES ${SRC_PATH}/attachment.cpp
${SRC_PATH}/message.cpp
${SRC_PATH}/messageaddress.cpp
${SRC_PATH}/plaintextmessage.cpp
${SRC_PATH}/smtpclientbase.cpp
${SRC_PATH}/smtpclient.cpp
${SRC_PATH}/sslsmtpclient.cpp
${SRC_PATH}/stringutils.cpp)
Expand Down Expand Up @@ -165,11 +164,14 @@ add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
add_executable(${PROJECT_UNITTEST_NAME} ${INCLUDE_PATH}
${TEST_SRC_PATH}/main.cpp
${TEST_SRC_PATH}/messageaddress_unittest.cpp
${TEST_SRC_PATH}/message_unittest.cpp
${TEST_SRC_PATH}/attachment_unittest.cpp
${TEST_SRC_PATH}/credential_unittest.cpp
${TEST_SRC_PATH}/plaintextmessage_unittest.cpp
${TEST_SRC_PATH}/stringutils_unittest.cpp
${TEST_SRC_PATH}/sslsmtpclient_unittest.cpp)
${TEST_SRC_PATH}/sslsmtpclient_unittest.cpp
${TEST_SRC_PATH}/smtpclientbase_unittest.cpp
${TEST_SRC_PATH}/smtpclient_unittest.cpp)

target_link_libraries(${PROJECT_UNITTEST_NAME} ${PROJECT_NAME} gtest gtest_main ${PTHREAD})
add_test(AllTestsInMain ${PROJECT_UNITTEST_NAME})
Expand All @@ -178,4 +180,4 @@ install (TARGETS ${PROJECT_NAME} DESTINATION lib)
install(DIRECTORY src/ DESTINATION include/smtpclient
FILES_MATCHING PATTERN "*.h")

#add_subdirectory("simpleclient")
add_subdirectory("simpleclient")
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main()
cerr << "An error occurred. Return code : " << err_no;
return 1;
}
cout << client.getServerReply() << endl;
cout << client.getCommunicationLog() << endl;
cout << "Operation completed!" << endl;
}
catch (invalid_argument &err)
Expand Down Expand Up @@ -78,7 +78,7 @@ int main()
cerr << "An error occurred. Return code : " << err_no;
return 1;
}
cout << client.getServerReply() << endl;
cout << client.getCommunicationLog() << endl;
cout << "Operation completed!" << endl;
}
catch (invalid_argument &err)
Expand Down
11 changes: 2 additions & 9 deletions src/attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const char *Attachment::getBase64EncodedFile() const
const char *Attachment::getMimeType() const
{
string filename_str { mFilename };
const string extension = toUppercase(filename_str.substr(filename_str.find_last_of('.') + 1));
const string extension = StringUtils::toUpper(filename_str.substr(filename_str.find_last_of('.') + 1));
//Images
if (extension == "PNG") {
return "image/png";
Expand Down Expand Up @@ -283,11 +283,4 @@ const char *Attachment::getMimeType() const
}

return "";
}

string Attachment::toUppercase(const string &pValue) const
{
string retval;
std::transform(pValue.begin(), pValue.end(), std::back_inserter(retval), ::toupper);
return retval;
}
}
1 change: 0 additions & 1 deletion src/attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace jed_utils
Attachment() = default;
char *mName;
char *mFilename;
std::string toUppercase(const std::string &pValue) const;
};
} // namespace jed_utils

Expand Down
26 changes: 18 additions & 8 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,25 @@ Message::Message(const MessageAddress &pFrom,
mAttachments(nullptr),
mAttachmentCount(pAttachmentsSize)
{
size_t subject_len = strlen(pSubject);
mSubject = new char[subject_len + 1];
strncpy(mSubject, pSubject, subject_len);
mSubject[subject_len] = '\0';
if (pSubject == nullptr) {
mSubject = new char('\0');
}
else {
size_t subject_len = strlen(pSubject);
mSubject = new char[subject_len + 1];
strncpy(mSubject, pSubject, subject_len);
mSubject[subject_len] = '\0';
}

size_t body_len = strlen(pBody);
mBody = new char[body_len + 1];
strncpy(mBody, pBody, body_len);
mBody[body_len] = '\0';
if (pBody == nullptr) {
mBody = new char('\0');
}
else {
size_t body_len = strlen(pBody);
mBody = new char[body_len + 1];
strncpy(mBody, pBody, body_len);
mBody[body_len] = '\0';
}

if (pTo != nullptr) {
mTo = new MessageAddress*[mToCount];
Expand Down
2 changes: 1 addition & 1 deletion src/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace jed_utils
size_t getBccCount() const;
Attachment **getAttachments() const;
size_t getAttachmentsCount() const;
protected:
private:
MessageAddress mFrom;
MessageAddress **mTo;
size_t mToCount;
Expand Down
Loading

0 comments on commit 178c34d

Please sign in to comment.