| 125 | } |
| 126 | |
| 127 | bool cMailMessage::GetAttachmentsAsString(std::string& s) |
| 128 | { |
| 129 | s.erase(); |
| 130 | bool allOK = true; |
| 131 | for (std::vector<TSTRING>::const_iterator at = mvstrAttachments.begin(); at != mvstrAttachments.end(); ++at) |
| 132 | { |
| 133 | s += "\r\n"; |
| 134 | |
| 135 | cFile file; |
| 136 | try |
| 137 | { |
| 138 | file.Open(at->c_str(), cFile::OPEN_READ); |
| 139 | |
| 140 | |
| 141 | // Simply stream the file into the socket. |
| 142 | // This will append the file as additional text. |
| 143 | const cFile::File_t cBufSize = 2048; |
| 144 | char buf[cBufSize]; |
| 145 | cFile::File_t bytes; |
| 146 | |
| 147 | while ((bytes = file.Read(buf, cBufSize)) != 0) |
| 148 | { |
| 149 | ASSERT(bytes > 0 && bytes <= cBufSize); // ensures typecast below |
| 150 | ASSERT((std::string::size_type)bytes < std::string().max_size()); |
| 151 | |
| 152 | s += std::string(buf, (size_t)bytes); |
| 153 | } |
| 154 | |
| 155 | file.Close(); |
| 156 | } |
| 157 | catch (eFile&) |
| 158 | { |
| 159 | // TODO: There is no method of reporting detailed information on |
| 160 | // errors if they occur. Perhaps someday there will be. At the moment |
| 161 | // it does not seem necessary as the only attached files that will |
| 162 | // be sent are temporary files that tripwire has just created. Thus |
| 163 | // the likelyhood of failure is low. |
| 164 | file.Close(); |
| 165 | allOK = false; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Send a new line to be sure the file ends properly |
| 170 | // Failure to do this could result in the "<CRLF>.<CRLF>" begin acknowledged as |
| 171 | // the end of the email message. |
| 172 | s += "\r\n"; |
| 173 | |
| 174 | return allOK; |
| 175 | } |
| 176 | |
| 177 | std::string cMailMessage::Create822Header() |
| 178 | { |