99
1010using namespace jed_utils ;
1111
12- Attachment::Attachment (const char *pFilename, const char *pName)
13- : mName(nullptr ), mFilename(nullptr ) {
12+ Attachment::Attachment (const char *pFilename, const char *pName, const char *pContentId )
13+ : mName(nullptr ), mFilename(nullptr ), mContentId( nullptr ) {
1414 size_t pFileNameLength = strlen (pFilename);
1515 if (pFileNameLength == 0 || StringUtils::trim (std::string (pFilename)).length () == 0 ) {
1616 throw std::invalid_argument (" filename" );
@@ -25,32 +25,44 @@ Attachment::Attachment(const char *pFilename, const char *pName)
2525 mName = new char [name_len+1 ];
2626 strncpy (mName , pName, name_len);
2727 mName [name_len] = ' \0 ' ;
28+
29+ size_t contentid_len = strlen (pContentId);
30+ mContentId = new char [contentid_len+1 ];
31+ strncpy (mContentId , pContentId, contentid_len);
32+ mContentId [contentid_len] = ' \0 ' ;
2833}
2934
3035Attachment::~Attachment () {
3136 delete[] mName ;
3237 mName = nullptr ;
3338 delete[] mFilename ;
3439 mFilename = nullptr ;
40+ delete[] mContentId ;
41+ mContentId = nullptr ;
3542}
3643
3744// Copy constructor
3845Attachment::Attachment (const Attachment& other)
3946 : mName(new char [strlen(other.mName ) + 1]),
40- mFilename(new char [strlen(other.mFilename ) + 1]) {
47+ mFilename(new char [strlen(other.mFilename ) + 1]),
48+ mContentId(new char [strlen(other.mContentId ) + 1]) {
4149 size_t name_len = strlen (other.mName );
4250 strncpy (mName , other.mName , name_len);
4351 mName [name_len] = ' \0 ' ;
4452 size_t filename_len = strlen (other.mFilename );
4553 strncpy (mFilename , other.mFilename , filename_len);
4654 mFilename [filename_len] = ' \0 ' ;
55+ size_t contentid_len = strlen (other.mContentId );
56+ strncpy (mContentId , other.mContentId , contentid_len);
57+ mContentId [contentid_len] = ' \0 ' ;
4758}
4859
4960// Assignment operator
5061Attachment& Attachment::operator =(const Attachment& other) {
5162 if (this != &other) {
5263 delete[] mName ;
5364 delete[] mFilename ;
65+ delete[] mContentId ;
5466 // mName
5567 size_t name_len = strlen (other.mName );
5668 mName = new char [name_len + 1 ];
@@ -61,35 +73,51 @@ Attachment& Attachment::operator=(const Attachment& other) {
6173 mFilename = new char [filename_len + 1 ];
6274 strncpy (mFilename , other.mFilename , filename_len);
6375 mFilename [filename_len] = ' \0 ' ;
76+ // mContentId
77+ size_t contentid_len = strlen (other.mContentId );
78+ mContentId = new char [contentid_len + 1 ];
79+ strncpy (mContentId , other.mContentId , contentid_len);
80+ mContentId [contentid_len] = ' \0 ' ;
6481 }
6582 return *this ;
6683}
6784
6885// Move constructor
6986Attachment::Attachment (Attachment&& other) noexcept
70- : mName(other.mName ), mFilename(other.mFilename ) {
87+ : mName(other.mName ), mFilename(other.mFilename ), mContentId(other. mContentId ) {
7188 // Release the data pointer from the source object so that the destructor
7289 // does not free the memory multiple times.
7390 other.mName = nullptr ;
7491 other.mFilename = nullptr ;
92+ other.mContentId = nullptr ;
7593}
7694
7795// Move assignement operator
7896Attachment& Attachment::operator =(Attachment&& other) noexcept {
7997 if (this != &other) {
8098 delete[] mName ;
8199 delete[] mFilename ;
100+ delete[] mContentId ;
82101 // Copy the data pointer and its length from the source object.
83102 mName = other.mName ;
84103 mFilename = other.mFilename ;
104+ mContentId = other.mContentId ;
85105 // Release the data pointer from the source object so that
86106 // the destructor does not free the memory multiple times.
87107 other.mName = nullptr ;
88108 other.mFilename = nullptr ;
109+ other.mContentId = nullptr ;
89110 }
90111 return *this ;
91112}
92113
114+ void Attachment::setContentId (const char * pContentId) {
115+ size_t contentid_len = strlen (pContentId);
116+ mContentId = new char [contentid_len + 1 ];
117+ strncpy (mContentId , pContentId, contentid_len);
118+ mContentId [contentid_len] = ' \0 ' ;
119+ }
120+
93121const char *Attachment::getName () const {
94122 return mName ;
95123}
@@ -98,6 +126,10 @@ const char *Attachment::getFilename() const {
98126 return mFilename ;
99127}
100128
129+ const char *Attachment::getContentId () const {
130+ return mContentId ;
131+ }
132+
101133const char *Attachment::getBase64EncodedFile () const {
102134 // Open the file
103135 std::ifstream in (mFilename , std::ios::in | std::ios::binary);
0 commit comments