🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #180092

My newsreader handles Asian posts/emails... with their raw 8 bit headers.

#180092
From: Jeff_℞elf
Date: Sat, 04 Feb 2006 05:00
74 lines
3987 bytes
Hi  »Q«,

As I said, I removed the raw 8 bit stuff from my headers because
Cotse.NET, my vitrual ISP was mangling my outgoing emails.

And, unlike Xnews, Dialog and Pan, 
my newsreader handles Asian posts/emails... with their raw 8 bit headers.

You told me:

  It's good to see that your current headers are properly encoded.
  Did you figure out the RFC yourself, 
  or did you use something written by someone else to fix your reader ?

I've known that encoding scheme for many years now,
I wrote the code myself, below. See X.CPP at Cotse.NET/users/jeffrelf

  #define  LOOP  while ( 1 )
  #define  Loop( N )  int J = - 1, LLL = N ; while ( ++ J < LLL )
  #define  LoopTo( StopCond )  \
    while (  \
       Ch && ( Ch = * ++ P )  \
    && ! ( Ch2 = P [ 1 ], StopCond ) )
  #define  _EqN  ! strncmp
  #define  _Str  sprintf
  #define Tics ( QueryPerformanceCounter( ( Quad * ) & _Tics ), _Tics )
  #define Secs ( _Secs = Tics / Secnd_Dub )

  typedef wchar_t  * LnP ; typedef  uchar  * _LnP ;  typedef char  * __LnP ;
  const int  Sz_Char = sizeof ( wchar_t );
  int  rv ;  double  _Secs, Due, Secnd_Dub ;
  ...

  QueryPerformanceFrequency( ( Quad * ) & Secnd );  Secnd_Dub = Secnd ;
  ...
  
  int Sz = WideCharToMultiByte( CP_UTF8, 0
  , Buff, -1, ( __LnP ) B_16, Buff_Room * Sz_Char, 0, 0 ) - 1 ;
  _LnP B_UTF_8 = ( _LnP ) B_16 ;  __LnP  B_Quoted = ( __LnP ) Buff ;  
  int  Sz_New_Header = 0, Sz_Old_Header = 0 ;  uchar High_Bit = 0x80 ;

  if ( _EqN( ( __LnP ) B_UTF_8, "Content-Type:", 13 ) ) {

    _LnP  P = B_UTF_8 ; __LnP  D = B_Quoted - 1 ;  uchar Ch = * P --, Ch2 ;
    LOOP {
      LoopTo( 
          Ch & High_Bit 
      ||  Ch == 13 && Ch2 == 10 && P [ 2 ] == 13 && P [ 3 ] == 10 ) 
        * ++ D = Ch ;
      
      if ( ! Ch ) {  Close ;  Sh ( L"¿ No Header ?" );  return -10 ; }
      if ( ! ( Ch & High_Bit ) ) {  * ++ D = 13, * ++ D = 10 ;
        Sz_New_Header = D - B_Quoted + 1 ;  Sz_Old_Header = P - B_UTF_8 + 2 ;
        break ; }
      D += _Str( ++ D, "=?UTF-8?Q?" ) - 1 ;   P -- ;  
      LoopTo( ! ( Ch & High_Bit ) )  D += _Str( ++ D, "=%x", Ch ) - 1 ;
      D += _Str( ++ D, "?=" ) - 1 ;  P -- ;  } }
  
  Loop( ( Sz_New_Header > 0 ) + 1 ) {  int  Sz_Send = Sz ;
    __LnP  B_Send = 
      ! Sz_New_Header 
    ? ( __LnP ) B_UTF_8 
    : ! J ? ( Sz_Send = Sz_New_Header, B_Quoted )
          : ( Sz_Send -= Sz_Old_Header, ( __LnP ) B_UTF_8 + Sz_Old_Header  );
    LOOP {  int  Sebt = send ( Connected, B_Send, Sz_Send, 0 );
      rv =  Sebt ==  Sz_Send ?  0 :  WSAGetLastError();
      if ( ! rv || rv != WSAEWOULDBLOCK )  break;  Due = Secs + 15 ;
      while ( 
          Secs < Due 
      &&  ! ( Allow ( WM_USER + 2 ) &&  * P_C2 == FD_WRITE ) )  Blink
      B_Send += Sebt ;  Sz_Send -= Sebt ; }
    if ( rv ) {  Close ;  Sh ( L"... Write Failed." );  return -4 ; } } 

Technical Details
Message-ID: <Jeff_Relf_2006_Feb_3_au1z@Cotse.NET>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!news.tu-darmstadt.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
References: <Jeff_Relf_2006_Feb_3_xcE9@Cotse.NET> <lihzx1anf1q4$.dlg@colin-jones.co.uk> <pan.2006.02.04.01.30.25.733062@thurston.blinkynet.net> <MrQ975FCB827129BitsmeitsQ@QsFQDN.dyndns.org> <Jeff_Relf_2006_Feb_3_BZz7@Cotse.NET> <MrQ975FDECBD25EDitsmeitsQ@QsFQDN.dyndns.org>

Show Full Headers
Complete Article Headers
Message-ID: <Jeff_Relf_2006_Feb_3_au1z@Cotse.NET>
Subject: My newsreader handles Asian posts/emails... with their raw 8 bit headers.
Date: Sat, 04 Feb 2006 05:00:09 +0000
From: Jeff_℞elf <Me@Privacy.NET>
References: <Jeff_Relf_2006_Feb_3_xcE9@Cotse.NET> <lihzx1anf1q4$.dlg@colin-jones.co.uk> <pan.2006.02.04.01.30.25.733062@thurston.blinkynet.net> <MrQ975FCB827129BitsmeitsQ@QsFQDN.dyndns.org> <Jeff_Relf_2006_Feb_3_BZz7@Cotse.NET> <MrQ975FDECBD25EDitsmeitsQ@QsFQDN.dyndns.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!news.tu-darmstadt.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
Newsgroups: news.software.readers
Lines: 74
Content-Type: text/plain; charset=UTF-8
X-Trace: individual.net TiDcesRqNWousRWzwbWJqgTYLvcgkKGgr2wdlQ7Lx4KhGHbf65