(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program htmail(input,output);

var
   line,adr   : varying [255] of char;
   ix,ix1,ix2 : integer;
   f1,f2      : text;

begin
   open(f1,'htmail.txt',old);
   reset(f1);
   open(f2,'htmail.html',new);
   rewrite(f2);
   writeln(f2,'<PRE>');
   while not(eof(f1)) do begin
      readln(f1,line);
      if (line=chr(12)) then line:='----';
      if ((index(line,'From:'+chr(9))=1) and 
          (index(line,'@')>0) and (index(line,'%')>0)) then begin
         ix:=index(substr(line,7,length(line)-6)+' ',' ');
         adr:=substr(line,7,ix-1);
         ix1:=1;
         while (adr[ix1]<>'"') do ix1:=ix1+1;
         ix2:=length(adr);
         while (adr[ix2]<>'"') do ix2:=ix2-1;
         adr:=substr(adr,ix1+1,ix2-ix1-1);
         line:='From:'+chr(9)+'<A HREF="mailto:'+adr+'">'+
               substr(line,7,ix-1)+'</A>'+substr(line,6+ix,length(line)-5-ix);
      end;
      if ((index(line,'To:'+chr(9))=1) and 
          (index(line,'@')>0) and (index(line,'%')>0)) then begin
         ix:=index(substr(line,5,length(line)-4)+' ',' ');
         adr:=substr(line,5,ix-1);
         ix1:=1;
         while (adr[ix1]<>'"') do ix1:=ix1+1;
         ix2:=length(adr);
         while (adr[ix2]<>'"') do ix2:=ix2-1;
         adr:=substr(adr,ix1+1,ix2-ix1-1);
         line:='To:'+chr(9)+'<A HREF="mailto:'+adr+'">'+
               substr(line,5,ix-1)+'</A>'+substr(line,4+ix,length(line)-3-ix);
      end;
      writeln(f2,line);
   end;
   writeln(f2,'</PRE>');
   close(f1);
   close(f2);
end.
