Skip to content

Commit d43ba75

Browse files
committed
Minor changes.
1 parent eebb649 commit d43ba75

File tree

3 files changed

+212
-10
lines changed

3 files changed

+212
-10
lines changed

MAIL/MAILClient.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ CMailClient::~CMailClient()
6969
* @param [in] strHost server address with or without port number
7070
* @param [in] strLogin username
7171
* @param [in] strPassword password
72-
* @param [in] ConnectionFlags optional.
72+
* @param [in] eSettingsFlags optional use | operator to choose multiple options
73+
* @param [in] eSslTlsFlags optional encryption type
7374
*
7475
* @retval true Successfully initialized the session.
7576
* @retval false The session is already initialized : call CleanupSession()
@@ -82,8 +83,8 @@ CMailClient::~CMailClient()
8283
*/
8384
const bool CMailClient::InitSession(const std::string& strHost, const std::string& strLogin,
8485
const std::string& strPassword,
85-
const SettingsFlag& SettingsFlags /* = ALL_FLAGS */,
86-
const SslTlsFlag& SslTlsFlags /* = NO_SSLTLS */)
86+
const SettingsFlag& eSettingsFlags /* = ALL_FLAGS */,
87+
const SslTlsFlag& eSslTlsFlags /* = NO_SSLTLS */)
8788
{
8889
if (strHost.empty())
8990
{
@@ -100,8 +101,8 @@ const bool CMailClient::InitSession(const std::string& strHost, const std::strin
100101
}
101102
m_pCurlSession = curl_easy_init();
102103

103-
m_eSettingsFlags = SettingsFlags;
104-
m_eSslTlsFlags = SslTlsFlags;
104+
m_eSettingsFlags = eSettingsFlags;
105+
m_eSslTlsFlags = eSslTlsFlags;
105106
m_strURL = strHost;
106107
ParseURL(m_strURL);
107108
m_strUserName = strLogin;

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
## About
6-
This is a simple Mail client for C++ 14. It wraps [libcurl][] for POP, SMTP and IMAP requests and meant to be a portable
6+
This is a simple Mail client for C++ 14. It wraps libcurl for POP, SMTP and IMAP requests and meant to be a portable
77
and easy-to-use API to perform e-mail related operations.
88

99
Compilation has been tested with:
@@ -64,7 +64,7 @@ CPOPClient POPClient([](const std::string& strLogMsg) { std::cout << strLogMsg <
6464
POPClient.InitSession("pop.gmail.com:995", "username@gmail.com", "password",
6565
CMailClient::SettingsFlag::ALL_FLAGS, CMailClient::SslTlsFlag::ENABLE_SSL);
6666

67-
std::string strEmailOne;
67+
std::string strEmail;
6868

6969
/* retrieve the mail number 1 and store it in strEmail */
7070
bool bResRcvStr = POPClient.GetString("1", strEmail);
@@ -92,7 +92,7 @@ to demonstrate the most useful methods.
9292

9393
## Callback to a Progress Function
9494

95-
A pointer to a callback progress meter function or a callable object (lambda, functor etc...), which should match the prototype shown below, can be passed.
95+
A pointer or a callable object (lambda, functor etc...) to of a progress meter function, which should match the prototype shown below, can be passed to a CMailClient object.
9696

9797
```cpp
9898
int ProgCallback(void* ptr, double dTotalToDownload, double dNowDownloaded, double dTotalToUpload, double dNowUploaded);
@@ -102,7 +102,7 @@ This function gets called by libcurl instead of its internal equivalent with a f
102102
103103
Returning a non-zero value from this callback will cause libcurl to abort the transfer.
104104
105-
The unit test "TestGetMailStringSSL" demonstrates how to use a progress function to display a progress bar on console.
105+
The unit test "TestGetMailStringSSL" already demonstrates how to use a progress function to display a progress bar on console.
106106
107107
## Thread Safety
108108
@@ -184,6 +184,7 @@ parameters only for the enabled tests. A template of the INI file exists already
184184
Example : (Run only SMTP with SSL tests)
185185

186186
```ini
187+
[tests]
187188
; POP without SSL/TLS are disabled
188189
pop=no
189190
; POP with SSL/TLS are disabled
@@ -222,7 +223,7 @@ valgrind --leak-check=full ./bin/Debug/test_mailclient /path_to_ini_file/conf.in
222223
The code coverage build doesn't use the static library but compiles and uses directly the
223224
MailClient-C++ API in the test program.
224225

225-
First of all, in TestMAIL/CMakeLists.txt, find and repalce :
226+
First of all, in TestMAIL/CodeCoverage.cmake, find and repalce :
226227
```
227228
"/home/amzoughi/Test/amine_mail_conf.ini"
228229
```

TestMAIL/CodeCoverage.cmake

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Copyright (c) 2012 - 2015, Lars Bilke
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without modification,
5+
# are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
#
30+
#
31+
# 2012-01-31, Lars Bilke
32+
# - Enable Code Coverage
33+
#
34+
# 2013-09-17, Joakim Söderberg
35+
# - Added support for Clang.
36+
# - Some additional usage instructions.
37+
#
38+
# 2017-01-15, Mohamed Amine Mzoughi
39+
# - Removed test helpers of mailclient-cpp from the code coverage.
40+
#
41+
# USAGE:
42+
43+
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
44+
# http://stackoverflow.com/a/22404544/80480
45+
#
46+
# 1. Copy this file into your cmake modules path.
47+
#
48+
# 2. Add the following line to your CMakeLists.txt:
49+
# INCLUDE(CodeCoverage)
50+
#
51+
# 3. Set compiler flags to turn off optimization and enable coverage:
52+
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
53+
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
54+
#
55+
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
56+
# which runs your test executable and produces a lcov code coverage report:
57+
# Example:
58+
# SETUP_TARGET_FOR_COVERAGE(
59+
# my_coverage_target # Name for custom target.
60+
# test_driver # Name of the test driver executable that runs the tests.
61+
# # NOTE! This should always have a ZERO as exit code
62+
# # otherwise the coverage generation will not complete.
63+
# coverage # Name of output directory.
64+
# )
65+
#
66+
# 4. Build a Debug build:
67+
# cmake -DCMAKE_BUILD_TYPE=Debug ..
68+
# make
69+
# make my_coverage_target
70+
#
71+
#
72+
73+
# Check prereqs
74+
FIND_PROGRAM( GCOV_PATH gcov )
75+
FIND_PROGRAM( LCOV_PATH lcov )
76+
FIND_PROGRAM( GENHTML_PATH genhtml )
77+
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR})
78+
79+
IF(NOT GCOV_PATH)
80+
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
81+
ENDIF() # NOT GCOV_PATH
82+
83+
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
84+
IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
85+
MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
86+
ENDIF()
87+
ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX)
88+
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
89+
ENDIF() # CHECK VALID COMPILER
90+
91+
SET(CMAKE_CXX_FLAGS_COVERAGE
92+
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
93+
CACHE STRING "Flags used by the C++ compiler during coverage builds."
94+
FORCE )
95+
SET(CMAKE_C_FLAGS_COVERAGE
96+
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
97+
CACHE STRING "Flags used by the C compiler during coverage builds."
98+
FORCE )
99+
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
100+
""
101+
CACHE STRING "Flags used for linking binaries during coverage builds."
102+
FORCE )
103+
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
104+
""
105+
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
106+
FORCE )
107+
MARK_AS_ADVANCED(
108+
CMAKE_CXX_FLAGS_COVERAGE
109+
CMAKE_C_FLAGS_COVERAGE
110+
CMAKE_EXE_LINKER_FLAGS_COVERAGE
111+
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
112+
113+
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
114+
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
115+
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
116+
117+
118+
# Param _targetname The name of new the custom make target
119+
# Param _testrunner The name of the target which runs the tests.
120+
# MUST return ZERO always, even on errors.
121+
# If not, no coverage report will be created!
122+
# Param _outputname lcov output is generated as _outputname.info
123+
# HTML report is generated in _outputname/index.html
124+
# Optional fourth parameter is passed as arguments to _testrunner
125+
# Pass them in list form, e.g.: "-j;2" for -j 2
126+
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
127+
128+
IF(NOT LCOV_PATH)
129+
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
130+
ENDIF() # NOT LCOV_PATH
131+
132+
IF(NOT GENHTML_PATH)
133+
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
134+
ENDIF() # NOT GENHTML_PATH
135+
136+
SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
137+
SET(coverage_cleaned "${coverage_info}.cleaned")
138+
139+
SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}")
140+
141+
# Setup target
142+
ADD_CUSTOM_TARGET(${_targetname}
143+
144+
# Cleanup lcov
145+
${LCOV_PATH} --directory . --zerocounters
146+
147+
# Run tests
148+
COMMAND ${test_command} ${ARGV3}
149+
150+
# Capturing lcov counters and generating report
151+
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
152+
COMMAND ${LCOV_PATH} --remove ${coverage_info} '/usr/*' 'simpleini/*' 'test_utils.cpp' 'test_utils.h' --output-file ${coverage_cleaned}
153+
COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
154+
COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned}
155+
156+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
157+
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
158+
)
159+
160+
# Show info where to find the report
161+
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
162+
COMMAND ;
163+
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
164+
)
165+
166+
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
167+
168+
# Param _targetname The name of new the custom make target
169+
# Param _testrunner The name of the target which runs the tests
170+
# Param _outputname cobertura output is generated as _outputname.xml
171+
# Optional fourth parameter is passed as arguments to _testrunner
172+
# Pass them in list form, e.g.: "-j;2" for -j 2
173+
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
174+
175+
IF(NOT PYTHON_EXECUTABLE)
176+
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
177+
ENDIF() # NOT PYTHON_EXECUTABLE
178+
179+
IF(NOT GCOVR_PATH)
180+
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
181+
ENDIF() # NOT GCOVR_PATH
182+
183+
ADD_CUSTOM_TARGET(${_targetname}
184+
185+
# Run tests
186+
${_testrunner} ${ARGV3}
187+
188+
# Running gcovr
189+
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}' -o ${_outputname}.xml
190+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
191+
COMMENT "Running gcovr to produce Cobertura code coverage report."
192+
)
193+
194+
# Show info where to find the report
195+
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
196+
COMMAND ;
197+
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
198+
)
199+
200+
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA

0 commit comments

Comments
 (0)