ReadArticleInGoogleGroups2

From 40tude Dialog Wiki

ReadArticleInGoogleGroups didn't work for me. So I wrote my own version, that doesn't use Postkey.


Program ReadArticleInGoogleGroups2;

uses
  Forms, StdCtrls;

const
   {Tag to detect a given Header}
   MessageIDHeader = 'Message-ID: ';
   
   CF_TEXT = 1;
   SW_SHOWNORMAL = 1;

var
  MessageID : string;                                      
  HeadersAreHidden : Boolean;


function OpenClipboard(hWndNewOwner: THandle): Boolean; external 'OpenClipboard@user32.dll stdcall';
function CloseClipboard: Boolean; external 'CloseClipboard@user32.dll stdcall';
function EmptyClipboard: Boolean; external 'EmptyClipboard@user32.dll stdcall';


function GlobalLock(hMem: THandle): Integer; external 'GlobalLock@kernel32.dll stdcall';
function GlobalUnlock(hMem: THandle): Boolean; external 'GlobalUnlock@kernel32.dll stdcall';

function ShellExecute(hWnd: THandle; Operation, FileName, Parameters,
  Directory: PChar; ShowCmd: Integer): THandle; external 'ShellExecuteA@shell32.dll stdcall';

function GetClipboardAsString: String;
var
  M: TMemo; F: TForm;
begin
  F:=TForm.Create(nil);
  M:=TMemo.Create(F);
  M.Parent:=F;
  M.PasteFromClipboard;
  Result:=M.Text;
  M.Free;
  F.Free;
end;

function GetMessageBody: String;
begin
  OpenClipboard(0);
  EmptyClipboard;
  CloseClipboard;
  ADo('ArticlePane');
  ADo('SelectAll');
  Ado('Copy');
  Result:=GetClipboardAsString;
end;

function GetHeaderInfo(HeaderTag, Body: String): String;
begin
  if Pos(#13#10+HeaderTag, Body)=0 then
    Result:=''
  else
    begin
    Delete(Body, 1, Pos(#13#10+HeaderTag, Body)+Length(HeaderTag)+1);
    Result:=Copy(Body, 1, Pos(#13#10, Body)-1);
    end;
end;

function AreHeadersHidden(Body: String): boolean;
begin
  if Pos(#13#10#13#10, Body)>0 then
    Body:=Copy(Body, 1, Pos(#13#10#13#10, Body)+1);
  Result:=Pos('Message-ID: ', Body)=0;
end;

function GetMessageId: String;
var
  Body: String;
begin
  Body:=GetMessageBody;
  HeadersAreHidden:=AreHeadersHidden(Body);
  {headers must be displayed to get messageID}
  if HeadersAreHidden then
    ADo('ShowHeaders');
  Body:=GetMessageBody;
  if HeadersAreHidden then
    Ado('ShowHeaders');

  Result:=GetHeaderInfo(MessageIDHeader, Body);
  {delete the < and > signs around message ID}
  Result:=copy(Result, 2, length(Result)-2);     

  OpenClipboard(0);
  EmptyClipboard;
  CloseClipboard;
end;


Begin
  MessageID:=GetMessageID;
  //WriteLn('MsgID: ' + MessageId);                                      

//This version of the script tries to compensate for the crappy GoogleGroups beta interface//
//and retrieves the source of the message instead of the formatted version//
// If you prefer to use the original version of this script just comment out the line below //
  ShellExecute(0, 'open', PChar('http://groups.google.com/groups?dmode=source&selm='+MessageID), '', '', 
SW_SHOWNORMAL);

// and use ShellExecute(0, 'open', PChar('http://groups.google.com/groups?selm='+MessageID), '', '', SW_SHOWNORMAL); instead //

End.