Graeme's Wiki

webnews and attachments

Type the code word, MONDAY here and then press to finish editing.



Last updated: 2008-10-08

The WebNews interface was added as an afterthought for those stuck behind firewalls that don't allow port 119 (news) through. At the time (about 4 years ago), I grabbed the first, easy to setup, web news server interface I could find. WebNews is a simple perl application that logs into the news server just like a normal GUI news reader would do. And no it doesn't decode attachments—it shows them as is in their base64 encoded format (lots of garbled text).

If you are stuck with the web interface only, then you can use the following program, included with FPC, that decodes base64 encoded text.

Compile it as follows:
 fpc b64dec.pp 

Save the base64 encoded text to a file. eg: in.txt

Normally the header just before the encoded text will tell you want the original filename was. eg: myattachment.zip

So no we simply need to run our application as follows:
 ./b64dec < in.txt > myattachment.zip 

You should now have the zip file in the current directory. It's not ideal, but it works in a pinch. By the way, there is a base64 encoder included with FPC as well. So you can use the web interface to include attachments as well.

PS:
If you know of a better web interface to news servers that also include attachment features, please let me know, and I would gladly review it - and if it works well, make it the new web interface. I'm running a Linux server, so Windows only solutions will not work.

Filename: b64dec.pp
// base64-decodes data from StdIn and writes the output to StdOut
// (c) 1999 Sebastian Guenther

{$MODE objfpc}

program b64dec;
uses classes, base64, sysutils;
var
 b64decoder: TBase64DecodingStream;
 InputStream: TStream;
 IsEnd: Boolean;
begin

 InputStream := THandleStream.Create(StdInputHandle);

 b64decoder := TBase64DecodingStream.Create(InputStream);

 IsEnd := False;
 while not IsEnd do
   try
     Write(Chr(b64decoder.ReadByte));
   except
     on e: EStreamError do IsEnd := True;
   end;

 b64decoder.Free;
 InputStream.Free;
end.

And here is the base64 encoder application.

Filename: b64enc.pp
// base64-encodes data from StdIn and writes the output to StdOut
// (c) 1999 Sebastian Guenther

{$MODE objfpc}

program b64enc;
uses classes, base64, sysutils;
var
  b64encoder: TBase64EncodingStream;
  InputStream, OutputStream: TStream;
  IsEnd: Boolean;
begin

  InputStream := THandleStream.Create(StdInputHandle);
  OutputStream := THandleStream.Create(StdOutputHandle);

  b64encoder := TBase64EncodingStream.Create(OutputStream);

  while not IsEnd do
    try
      b64encoder.WriteByte(InputStream.ReadByte);
    except
      on e: EStreamError do IsEnd := True;
    end;

  b64encoder.Free;
  InputStream.Free;
  OutputStream.Free;
end.

The original encoder/decoder files can be found in Free Pascal Compiler source directory:
 <fpcsrc>/packages/fcl-base/examples/ 

Regards,
- Graeme -