Originally Posted by
marcel
This is what I was asking.
If you encode the data to base 64 before sending it.
Also, I asked if you tested this base 64 encoding/decoding locally.
Maybe you don't decode from base64 ok.
Regards
The decoding from base64 is taken care by smtp once I use
Content-Transfer-Encoding: base64
after the DATA tag used for smtp.
I imagine you cannot post the code, but are you sure there aren't any differences between plain files? Not even a byte?
Do you handle well SMTP transparency and the end of data message indicator?
Because a plain file might work even if you miss a byte, but an encoded file won't.
I can here is the small sample
void SynsupMail::sendMessage()
{
string msg;
QFile f
( textFilename
->text
() );
//textFilename->text() contains file path. The file can be en //encrypted using AES::CBC or a plain text
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
// read the contents of the file into message
while( ! t.eof() )
{
message += t.readLine();
message += "\n";
}
f.close();
//encode the data using base64 using crypto++ library for Qt3, in Qt4
//there is a function tobase64().
StringSource (string(message.data()), true, new Base64Encoder(new StringSink(msg))) ;
Smtp *smtp = new Smtp( textFrom->text(), textTo->text(), textSubject->text(),
}
}
void SynsupMail::sendMessage()
{
QString message;
string msg;
QFile f ( textFilename->text() ); //textFilename->text() contains file path. The file can be en
//encrypted using AES::CBC or a plain text
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
QTextStream t ( &f );
// read the contents of the file into message
while( ! t.eof() )
{
message += t.readLine();
message += "\n";
}
f.close();
//encode the data using base64 using crypto++ library for Qt3, in Qt4
//there is a function tobase64().
StringSource (string(message.data()), true, new Base64Encoder(new StringSink(msg))) ;
Smtp *smtp = new Smtp( textFrom->text(), textTo->text(), textSubject->text(),
QString(msg.data()), fileName, );
}
}
To copy to clipboard, switch view to plain text mode
All the code in smtp.cpp is same as that of /examples/network/mail except this
else if in function void Smtp::readyRead(). I made this modification to
send the file as an attachment
else if ( state == Body && responseLine[0] == '3' )
{
version
+= QString("MIME-Version: 1.0\r\n");
Header
+= QString("Content-Type: multipart/mixed; ") + QString("boundary=unique-boundary-1\r\n") ;
headerContent
+= QString("--unique-boundary-1\r\n");
headerContent
+= QString("Content-Type: application/octet-stream ") + QString("\r\n");
headerContent
+= QString("Content-Transfer-Encoding: base64\r\n");
headerContent
+= QString("Content-Disposition: attachment;") + QString( "filename=" ) + _fileName ;
//t is QTextStream
*t << version;
*t << address;
*t << Header;
*t << headerContent;
*t << message;
closeTag
+= QString("--unique-boundary-1--\r\n");
*t << closeTag << ".\r\n";
state = Quit;
}
else if ( state == Body && responseLine[0] == '3' )
{
QString fileName("");
QString version;
version += QString("MIME-Version: 1.0\r\n");
QString Header;
Header += QString("Content-Type: multipart/mixed; ") +
QString("boundary=unique-boundary-1\r\n") ;
QString headerContent;
headerContent += QString("--unique-boundary-1\r\n");
headerContent += QString("Content-Type: application/octet-stream ") + QString("\r\n");
headerContent += QString("Content-Transfer-Encoding: base64\r\n");
headerContent += QString("Content-Disposition: attachment;") +
QString( "filename=" ) + _fileName ;
//t is QTextStream
*t << version;
*t << address;
*t << Header;
*t << headerContent;
*t << message;
QString closeTag;
closeTag += QString("--unique-boundary-1--\r\n");
*t << closeTag << ".\r\n";
state = Quit;
}
To copy to clipboard, switch view to plain text mode
These are the things that happen,
Plain text file--->
plaintext file --> Encoding base64 --> Over N/w --> SMTP decodes base64 --> plaintext file to receiver
Encrypted file (encrypted with AES::CBC)--->
Encrypted file --> Encoding base64 --> Over N/w --> SMTP decodes base64 --> Encrypted file
M i doing anything wrong above ?
Bookmarks