yEnc decoder

M

Marvin Grill

Hi, I'm working on a type of NewsHound program and am stuck on how to
decode the yEnc encoded articles (body).

I tried using Joe Feser's yEnc class but can't seem to get it to work
properly
Not sure whether it's an Encoding.Type problem or not getting the
stream start position right.

In any case here's part of the code with the problem:

_________________________________________________________________
Article = 21971499;
nntp1.Send("BODY " + Article.ToString() + "\r\n");
// this line reads stream till line with period only
s = nntp1.Receive(".\r\n");
Stream inMemStream, outMemStream;
inMemStream= new MemoryStream(Encoding.UTF8.GetBytes(s));
outMemStream= new MemoryStream();
inMemStream.Seek(0, 0);
yenc.DecodeFromRawStream(inMemStream, outMemStream);
outMemStream.Seek(0, 0);

StreamReader sr = new StreamReader(outMemStream, Encoding.UTF8);
string ArticleAttachment = sr.ReadToEnd();
______________________________________________________________________

The problem is that the decoded string has only the upper case letters
right but the lower case letters are spaces.


If any one knows of any other components out there that can decode
yEnc please let me know.

Thanks
Marv
 
O

One Handed Man [ OHM# ]

Hey, you're not related to the 'George Foreman Grill' are you ?

OHM#
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Marvin Grill) scripsit:
Article = 21971499;
nntp1.Send("BODY " + Article.ToString() + "\r\n");
// this line reads stream till line with period only
s = nntp1.Receive(".\r\n");
Stream inMemStream, outMemStream;
inMemStream= new MemoryStream(Encoding.UTF8.GetBytes(s));
outMemStream= new MemoryStream();
inMemStream.Seek(0, 0);
yenc.DecodeFromRawStream(inMemStream, outMemStream);
outMemStream.Seek(0, 0);

StreamReader sr = new StreamReader(outMemStream, Encoding.UTF8);
string ArticleAttachment = sr.ReadToEnd();

Seems to be C# code, that's OT in this group...
 
M

Marvin Grill

Armin Zingler said:
You know that you've also posted to the VB.NET group?

Yes Armin I realized that but I have a two-fold question. The second
part is asking for information on ANY components known that could do
yEnc decoding --- which can be written in either C# or VB

But thanks for your constructive criticism even though it did not help
with my question in any way what so ever.

Regards
Marvin Grill
 
D

Daniel O'Connell

If my memory serves right, this code should work(I wrote it a long time ago
and I don't know for sure if it was 100% working, I know it was working with
the test files):
byte[] yEncDecodeBlock(byte[] Block)
{
byte x;
byte[] O = new byte[Block.Length];
byte[] Out;
int count = 0;
for (int i=0;i < Block.Length; i++)
{
x = Block;
if (x=='\r')
{

i++;
if (Block == '\n')
{
continue;
}
else
{
throw new yEncInvalidFormatException("There was a carriage return
without a linefeed detected");
}
}
else if (x=='=')
{
i++;
byte r = x;
x = Block;
O[count] = (byte)(x-64-42);
}
else
{
O[count] = (byte)(x-42);
}
count++;
}
if (count != 0)
{
Out = new byte[count];
Buffer.BlockCopy(O,0,Out,0,count);
return Out;
}
return null;
}
 
M

Marvin Grill

Daniel thanks very much for your reply. You are the first person to
add anything intelligent to this thread so far. You are a gentleman.
I'll give it a try and post a reply for others to benefit.

Marv

Daniel O'Connell said:
If my memory serves right, this code should work(I wrote it a long time ago
and I don't know for sure if it was 100% working, I know it was working with
the test files):
byte[] yEncDecodeBlock(byte[] Block)
{
byte x;
byte[] O = new byte[Block.Length];
byte[] Out;
int count = 0;
for (int i=0;i < Block.Length; i++)
{
x = Block;
if (x=='\r')
{

i++;
if (Block == '\n')
{
continue;
}
else
{
throw new yEncInvalidFormatException("There was a carriage return
without a linefeed detected");
}
}
else if (x=='=')
{
i++;
byte r = x;
x = Block;
O[count] = (byte)(x-64-42);
}
else
{
O[count] = (byte)(x-42);
}
count++;
}
if (count != 0)
{
Out = new byte[count];
Buffer.BlockCopy(O,0,Out,0,count);
return Out;
}
return null;
}
Marvin Grill said:
Hi, I'm working on a type of NewsHound program and am stuck on how to
decode the yEnc encoded articles (body).

I tried using Joe Feser's yEnc class but can't seem to get it to work
properly
Not sure whether it's an Encoding.Type problem or not getting the
stream start position right.

In any case here's part of the code with the problem:

_________________________________________________________________
Article = 21971499;
nntp1.Send("BODY " + Article.ToString() + "\r\n");
// this line reads stream till line with period only
s = nntp1.Receive(".\r\n");
Stream inMemStream, outMemStream;
inMemStream= new MemoryStream(Encoding.UTF8.GetBytes(s));
outMemStream= new MemoryStream();
inMemStream.Seek(0, 0);
yenc.DecodeFromRawStream(inMemStream, outMemStream);
outMemStream.Seek(0, 0);

StreamReader sr = new StreamReader(outMemStream, Encoding.UTF8);
string ArticleAttachment = sr.ReadToEnd();
______________________________________________________________________

The problem is that the decoded string has only the upper case letters
right but the lower case letters are spaces.


If any one knows of any other components out there that can decode
yEnc please let me know.

Thanks
Marv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top