PDA

View Full Version : Download attachments and Base64 coding



Altertwin
14th March 2010, 16:19
I'm making tiny e-mail application downloading attachments from server POP3. I used QByteArray::fromBase64 to decode files. I haven't got problems with *.txt files but I can't download and save e.g. *.png files. Images files are dameged. This is my code:



QByteArray hashAtt;
for( ... )
{
(...)
hashAtt.append(lines[i]);
(...)
}

QFile file(fileName);

if(file.open(QFile::WriteOnly | QFile ::Text))
{
QByteArray fileAtt = QByteArray::fromBase64(hashAtt);
QTextStream out(&file);
out << hashAtt;
hashAtt.clear();
}



What should I do to correctly download all attachments from host?

squidge
14th March 2010, 18:12
On the image files that come out corrupted, what does the content-encoding header say?

There's no guarantee that every mail client will use base64. It's the most common, but not the only encoding, hence the reason for the header.