Initial
This commit is contained in:
75
yproxy/hold/NewsDecoder.cpp
Normal file
75
yproxy/hold/NewsDecoder.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <yproxy/NewsDecoder.hpp>
|
||||
#include <yproxy/ydecode.hpp>
|
||||
#include <uuencode/uuencode.hpp>
|
||||
#include <common/array.hpp>
|
||||
|
||||
bool NewsDecoder::decode(const String &pathFileName,Block<String> &uuencodedText)
|
||||
{
|
||||
Block<String> articleText;
|
||||
String strLine;
|
||||
File inFile;
|
||||
|
||||
uuencodedText.remove();
|
||||
if(!inFile.open(pathFileName,"rb"))return false;
|
||||
while(inFile.readLine(strLine))articleText.insert(&strLine);
|
||||
inFile.close();
|
||||
return decode(pathFileName,articleText,uuencodedText);
|
||||
}
|
||||
|
||||
bool NewsDecoder::decode(const String &messageID,Block<String> &articleText,Block<String> &uuencodedLines)
|
||||
{
|
||||
Block<String> replaceBlock;
|
||||
String pathImageFileName;
|
||||
String pathTempFileName;
|
||||
File outFile;
|
||||
File inFile;
|
||||
int beginIndex;
|
||||
int endIndex;
|
||||
int index;
|
||||
Array<BYTE> bytes;
|
||||
|
||||
uuencodedLines.remove();
|
||||
if(!isYEnc(articleText,beginIndex,endIndex))return false;
|
||||
pathTempFileName=messageID+".yenc";
|
||||
if(!outFile.open(pathTempFileName,"wb"))return false;
|
||||
for(index=beginIndex;index<=endIndex;index++)outFile.writeLine(articleText[index]);
|
||||
outFile.close();
|
||||
YDecoder::decode(pathTempFileName,pathImageFileName,YDecoder::ForceDecode);
|
||||
::unlink(pathTempFileName);
|
||||
if(!inFile.open(pathImageFileName,"rb"))return false;
|
||||
bytes.size(inFile.length());
|
||||
inFile.read(&bytes[0],bytes.size());
|
||||
if(!UUEncode::encode(bytes,pathImageFileName,replaceBlock))return false;
|
||||
for(index=0;index<beginIndex;index++)uuencodedLines.insert(&articleText[index]);
|
||||
for(index=0;index<replaceBlock.size();index++)uuencodedLines.insert(&replaceBlock[index]);
|
||||
return uuencodedLines.size()?true:false;
|
||||
}
|
||||
|
||||
bool NewsDecoder::isYEnc(Block<String> &articleText,int &beginIndex,int &endIndex)
|
||||
{
|
||||
int index;
|
||||
beginIndex=-1;
|
||||
endIndex=-1;
|
||||
|
||||
for(index=0;index<articleText.size();index++)
|
||||
{
|
||||
String &strLine=articleText[index];
|
||||
if(strLine.substr(0,6)=="=ybegin")
|
||||
{
|
||||
beginIndex=index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(-1==beginIndex)return false;
|
||||
for(;index<articleText.size();index++)
|
||||
{
|
||||
String &strLine=articleText[index];
|
||||
if(strLine.substr(0,4)=="=yend")
|
||||
{
|
||||
endIndex=index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user