Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/nntp/NntpArticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@
ushort NntpArticle::sNbMaxTrySending = 5;

NntpArticle::NntpArticle(NntpFile *file, uint part, qint64 pos, qint64 bytes,
const std::string *from, bool obfuscation):
const std::string *from, bool obfuscateArticles):
_nntpFile(file), _part(part),
_id(QUuid::createUuid()),
_from(from),
_subject(nullptr),
_body(nullptr),
_filePos(pos), _fileBytes(bytes),
_obfuscateArticles(obfuscateArticles),
_nbTrySending(0),
_msgId()
{
file->addArticle(this);
connect(this, &NntpArticle::posted, _nntpFile, &NntpFile::onArticlePosted, Qt::QueuedConnection);
connect(this, &NntpArticle::failed, _nntpFile, &NntpFile::onArticleFailed, Qt::QueuedConnection);

if (!obfuscation)
if (!obfuscateArticles)
{
std::stringstream ss;
ss << _nntpFile->nameWithQuotes().toStdString() << " (" << part << "/" << _nntpFile->nbArticles() << ")";
Expand All @@ -54,6 +55,21 @@ NntpArticle::NntpArticle(NntpFile *file, uint part, qint64 pos, qint64 bytes,
}
}

std::string generateRandomString(int length)
{
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

std::string randomString;
for (int i = 0; i < length; ++i) {
randomString += alphanum[rand() % (sizeof(alphanum) - 1)];
}

return randomString;
}

void NntpArticle::yEncBody(const char data[])
{
// do the yEnc encoding
Expand All @@ -63,8 +79,19 @@ void NntpArticle::yEncBody(const char data[])

// format the body
std::stringstream ss;
std::string filename;
if (_obfuscateArticles)
{
// Generate a random string for the filename
const int randomStringLength = 32 + (rand() % 31); // between 32-62 length
filename = generateRandomString(randomStringLength);
}
else
filename = _nntpFile->fileName();

// Use the generated random string as the filename
ss << "=ybegin part=" << _part << " total=" << _nntpFile->nbArticles() << " line=128"
<< " size=" << _nntpFile->fileSize() << " name=" << _nntpFile->fileName() << Nntp::ENDLINE
<< " size=" << _nntpFile->fileSize() << " name=" << filename << Nntp::ENDLINE
<< "=ypart begin=" << _filePos + 1 << " end=" << _filePos + _fileBytes << Nntp::ENDLINE
<< yencBody << Nntp::ENDLINE
<< "=yend size=" << _fileBytes << " pcrc32=" << std::hex << crc32 << Nntp::ENDLINE
Expand Down Expand Up @@ -163,4 +190,4 @@ void NntpArticle::dumpToFile(const QString &path, const std::string &articleIdSi
file.write(header(articleIdSignature).c_str());
file.write(_body);
file.close();
}
}
3 changes: 2 additions & 1 deletion src/nntp/NntpArticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class NntpArticle : public QObject

const qint64 _filePos; //!< position in the File (for yEnc header)
const qint64 _fileBytes; //!< bytes of the original file that are encoded
const bool _obfuscateArticles;

ushort _nbTrySending;

Expand Down Expand Up @@ -138,4 +139,4 @@ void NntpArticle::overwriteMsgId(const QString &serverMsgID){ _msgId = serverMsg
ushort NntpArticle::nbMaxTrySending() { return sNbMaxTrySending; }
void NntpArticle::setNbMaxRetry(ushort nbMax) { sNbMaxTrySending = nbMax; }

#endif // NntpArticle_H
#endif // NntpArticle_H