Hi marcel, I modified the code as you said. I'm unable to
revert the operation after receiving the file, the contents
gets deleted, Can you please check the code below.
//Sending message------>
void SynsupMail::sendMessage()
{
string msg;
QFile f
( textFilename
->text
() );
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
dat = f.readAll();
}
else
{
// problems opening the file - emit a warning message
tr("Error opening file %1").arg( textFilename->text() ) );
enableSubmit();
return;
}
f.close();
StringSource
( string
(QString(dat
).
data()),
true,
new Base64Encoder
(new StringSink
(msg
)));
Smtp *smtp = new Smtp( textFrom->text(), textTo->text(),
textSubject->text(),
}
void SynsupMail::sendMessage()
{
QByteArray dat;
string msg;
QFile f ( textFilename->text() );
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
dat = f.readAll();
}
else
{
// problems opening the file - emit a warning message
QMessageBox::warning( this, tr("error"),
tr("Error opening file %1").arg( textFilename->text() ) );
enableSubmit();
return;
}
f.close();
StringSource ( string(QString(dat).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
{
address
= QString::fromLatin1( "From: " ) + from
+ QString::fromLatin1( "\nTo: " ) + to
+ QString::fromLatin1( "\nSubject: " ) + subject
+ "\n";
message
= QString::fromLatin1( "\n\n" ) + body
+ "\n";
/*replace( message, QString::fromLatin1( "\n" ),
QString::fromLatin1( "\r\n" ) );*/
replace
( message,
QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
replace
( address,
QString::fromLatin1( "\n" ),
replace
( address,
QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
}
Smtp::Smtp( const QString &from, const QString &to,
const QString &subject,
const QString &body, const QString &fileName)
{
address = QString::fromLatin1( "From: " ) + from +
QString::fromLatin1( "\nTo: " ) + to +
QString::fromLatin1( "\nSubject: " ) + subject + "\n";
message = QString::fromLatin1( "\n\n" ) + body + "\n";
/*replace( message, QString::fromLatin1( "\n" ),
QString::fromLatin1( "\r\n" ) );*/
replace( message, QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
replace( address, QString::fromLatin1( "\n" ),
QString::fromLatin1( "\r\n" ) );
replace( address, QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
}
To copy to clipboard, switch view to plain text mode
//Receiving message------>
int SysupClass::openFile( const char* infile )
{
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
dat = f.readAll();
}
else
{
f.close();
return -1;
}
f.close();
//Here I might not be correct to reverse the operation
//i.e removing \r\n..\r\n
/*QString ss = dat;
replace( ss, QString::fromLatin1( "\r\n..\r\n" ),
QString::fromLatin1( "\r\n.\r\n" ) );*/
QFile f1
( strcat(infile,
".mod") );
if ( f1.open (IO_WriteOnly|IO_Truncate) )
{
// file opened successfully
f1.writeBlock(ss, ss.length());
}
f1.close();
//decrypt the file with AES::CBC mode
}
int SysupClass::openFile( const char* infile )
{
QByteArray dat;
QFile f ( infile );
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
dat = f.readAll();
}
else
{
f.close();
return -1;
}
f.close();
//Here I might not be correct to reverse the operation
//i.e removing \r\n..\r\n
/*QString ss = dat;
replace( ss, QString::fromLatin1( "\r\n..\r\n" ),
QString::fromLatin1( "\r\n.\r\n" ) );*/
QFile f1 ( strcat(infile, ".mod") );
if ( f1.open (IO_WriteOnly|IO_Truncate) )
{
// file opened successfully
f1.writeBlock(ss, ss.length());
}
f1.close();
//decrypt the file with AES::CBC mode
}
To copy to clipboard, switch view to plain text mode
wysota--->
I'm unable to understand these points
3. divide it into blocks 64 (or 80 or whatever) bytes each ---- need some more explanation
4. concatenate blocks using newlines (\r\n) ----- ---- need some more explanation
5. pass the result into the mail stream adding a base64 header --------- ---- need some more explanations
If possible please correct me with my code above and tell me how can I achieve the above three points
Bookmarks