-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
corrupt attachments: contentHandler issue? #93
Comments
Hi! I didn't really understood the problem. Could you please provide a minimal working example code which reproduces the problem, the result that is expected, and the result that is actually returned. By the way, does the problem also occur with smaller contents? Thanks, Vincent |
Hi! Please apologize for the late reply. One more question: at which moment do you create the file "my_file_email.dat"? This is not in the example code you provided. Is it the result of a msg->generate(), or the attachment you get after the message has been sent over SMTP and received in your mailbox? In the later case, are you sure the extra chars are not added by a gateway during the transfer of the message? Please send me the exact code you used to produce the two files, so that I can reproduce the problem in the same conditions. Thanks, Vincent |
Hi Vincent, Thank you for your answer. I appreciate it. The full code is in my last message. I get "my_file_email.dat" from my email client Outlook 2003 SP3. I did some more tests and:
I guess the bug is somewhere in the "charset conv". I compiled vmime with VMIME_CHARSETCONV_LIB_IS_WIN=1, perhaps I should try with iconv. Thanks. |
Hi! Finally, did you try with another charset conversion library? The result of testing this should be a good hint to find out where the issue occurs. Thanks, Vincent |
Hi! Could you try the following program? (I used "/tmp" instead of "c:" on Linux) #include <iostream>
#include <fstream>
// vmime
#include <vmime/vmime.hpp>
using namespace std;
using namespace vmime;
int main()
{
try
{
messageBuilder mb;
// construct 10MB dummy file
string my_file("");
for (int i=0; i<(10000*1024); ++i)
my_file+="1";
// and save it with ofstream
std::ofstream sortie("/tmp/my_file_ofstream.dat", ios::binary);
sortie << my_file << flush;
// and attach it to email
shared_ptr<contentHandler> cth = make_shared<stringContentHandler>( my_file);
shared_ptr<attachment> att1 = make_shared<defaultAttachment>(cth, mediaType(mediaTypes::APPLICATION_OCTET_STREAM, mediaTypes::APPLICATION_OCTET_STREAM), text("my_file"), word("my_file_email.dat") );
mb.appendAttachment(att1);
// send the email
mb.getRecipients().appendAddress( make_shared<mailbox>("test@example.com") );
mb.setSubject( text("my file test") );
mb.setExpeditor( mailbox(text("test"), "test@test.com"));
shared_ptr<message> msg = mb.construct();
vmime::string msgData = msg->generate();
vmime::messageParser mp(msgData);
for (int i = 0 ; i < mp.getAttachmentCount() ; ++i)
{
const vmime::attachment& att = *mp.getAttachmentAt(i);
shared_ptr <const contentHandler> data = att.getData();
std::ofstream sortie("/tmp/my_file_ofstream2.dat", ios::binary);
vmime::utility::outputStreamAdapter osa(sortie);
data->extract(osa);
}
}
// VMime exception
catch (vmime::exception& e)
{
std::cout << "vmime::exception: " << e.what() << std::endl;
throw;
}
// Standard exception
catch (std::exception& e)
{
std::cout << "std::exception: " << e.what() << std::endl;
throw;
}
std::cout << std::endl;
return 0;
} Then, do a "diff" on the two files:
On my host, it found no diff between the files. I am using the latest version of VMime from Git. Could you tell me if there are on yours? I will try some other tests to see whether there could be a problem when sending data over the SMTP stream. |
Hi, With your code on my machine, files are identical. |
Hello! Thank you for testing. Finally, I found the issue. It was a bad pointer offsetting when copying data to the actual send buffer, when using SMTP BDAT chunking (the problem did not occur with normal DATA command). Here is the fix I committed: 07ae82f |
Hello,
I've just compiled the latest source of vmime with g++ 4.9.0 (i686-win32-dwarf-rev2, Built by MinGW-W64 project).
With this simple code:
messageBuilder mb
shared_ptr«contentHandler» cth = make_shared«stringContentHandler»( "8MB string here");
shared_ptr«attachment» att1 = make_shared«defaultAttachment»(cth, mediaType(mediaTypes::APPLICATION_OCTET_STREAM, mediaTypes::APPLICATION_OCTET_STREAM), text("toto"), word("toto.txt") ); mb.appendAttachment(att1);
I get like 2 modified characters inside the attachment, each 2MB or so... (didn't really find any scheme in that).
When I write the string in a file with std::ofstream, the file content has no problem.
Any clue?
Thanks for the help :)
The text was updated successfully, but these errors were encountered: