Article View: news.software.readers
Article #127559[Dialog] Customising Posts
From: Alain GUERIN
Date: Wed, 02 Jul 2003 19:40
Date: Wed, 02 Jul 2003 19:40
180 lines
7062 bytes
7062 bytes
Hello,
In a precedent discussion I told how I tried to modified the editing window
with postkey, in order to have the hello message in the language of the
news group.
I failed as there was no way to open by program the newsgroup
list and detect the newsgroup.
>From the script made by matija and the advises from Juergen Haible, I try
by another way and now I have it.
This new script is working for new posts and for following posts.
It add a line at the beginning of the post depending on the newsgroup.
I sent a first buggy version in a post (now canceled) without Dialog in the
subject. (That will be the next modification: add the Dialog tag when
sending a new post in the newsmanager groups).
So this version seems to work better and has one more feature : adaptation
to the day time.
The bug was caused by the way I calculated the place to insert the prompt in
the first line of the message, after all the headers. There are cases, when
acute letters are in the subject for example, where one header can be in two
strings of the message.strings list. As I was testing the ":" to find the
first line after the header, in that case, it was wrong.
I now search for the agent name that seems to be the last header before
sending the message in a newsgroup. But it is not an absolute secure way.
;-/
program OnBeforeSendingMessage;
type
TLanguage = (LFrench, LEnglish, LGerman);
TDayTime = (DTMorning, DTDay, DTAfternoon, DTEvening, DTNight);
function FindLanguage(VAR List : TStringList; LanguageFileName: string;
NewsHeader : string): boolean;
begin
list.LoadFromFile(LanguageFileName);
Result := list.indexof(NewsHeader) > -1
(* where each line is a newsgroup in the language tested:
Newsgroups: news.software.readers
Newsgroups: carlokok.public.pascalscript
This function could be modify to avoy to have 'Newsgroups: ' in each line of
the text file by deleting it from Newsheader *)
end;
function SelectLanguage(NewsHeader : String):TLanguage;
var
list: TStringList;
begin
Result := LFrench;
list := TStringList.Create();
IF FindLanguage(List,'C:\Mes documents\English groups.txt',NewsHeader)
THEN
Result := LEnglish
ELSE
IF FindLanguage(List,'C:\Mes documents\German groups.txt',NewsHeader)
THEN
Result := LGerman;
list.free;
(* or in code option:
IF (POS('news.software.readers', NewsHeader) > 0)
OR (POS('carlokok.public.pascalscript', NewsHeader) > 0) THEN
Result := LEnglish;
but it is case sensitive in this way ;-)
*)
end;
function SelectTime(NewsHeader : String): TDayTime;
VAR
hour : BYTE;
begin
delete(NewsHeader,1,pos(':',NewsHeader));
delete(NewsHeader,1,pos(':',NewsHeader)-3);
delete(NewsHeader,pos(':',NewsHeader),Length(NewsHeader)-2);
hour := strtoint(NewsHeader);
case hour of
5: result := DTMorning;
6: result := DTMorning;
7: result := DTMorning;
8: result := DTDay;
9: result := DTDay;
10: result := DTDay;
11: result := DTDay;
12: result := DTDay;
13: result := DTDay;
14: result := DTAfternoon;
15: result := DTAfternoon;
16: result := DTAfternoon;
17: result := DTAfternoon;
18: result := DTEvening;
19: result := DTEvening;
20: result := DTEvening;
21: result := DTEvening;
22: result := DTEvening;
else
result := DTNight
end;
end;
function OnBeforeSendingMessage(var Message: TStringlist; Servername:
string; IsEmail: boolean):boolean;
var
HeaderCount : INTEGER;
InsertionPlace : INTEGER;
InsertionContent : String;
Language : TLanguage;
TimePeriod : TDayTime;
begin
//Your code goes here
//Return false to prevent sending the passed message
IF NOT IsEMail THEN
BEGIN
HeaderCount := 0;
WHILE (HeaderCount < Message.count) AND (pos('Newsgroups:',
Message.Strings[HeaderCount]) <> 1) DO
HeaderCount:=HeaderCount+1;
IF HeaderCount < Message.count THEN
BEGIN
Language := SelectLanguage(Message.Strings[HeaderCount]);
HeaderCount := 0;
TimePeriod := DTDay;
WHILE (HeaderCount < Message.count) AND (pos('User-Agent:
40tude_Dialog', Message.Strings[HeaderCount]) <> 1) DO
BEGIN
IF pos('Date:', Message.Strings[HeaderCount]) = 1 THEN
TimePeriod := SelectTime(Message.Strings[HeaderCount]);
HeaderCount:=HeaderCount+1;
END;
IF HeaderCount < Message.count THEN
InsertionPlace:=HeaderCount + 2;
InsertionContent :='';
case Language of
LFrench :
case TimePeriod of
DTMorning :
InsertionContent :='Bon Matin,';
DTDay :
InsertionContent :='Bonjour,';
DTAfternoon :
InsertionContent :='Bon(ne) aprรจs-midi,';
DTEvening :
InsertionContent :='Bonsoir,';
DTNight :
InsertionContent :='Bonne nuit,';
end;
LEnglish:
InsertionContent :='Hello,';
LGerman:
InsertionContent :='Guten Tag,';
end;
IF (InsertionPlace > 0) AND (InsertionPlace < Message.Count) AND
(InsertionContent <>'') THEN
message.insert (InsertionPlace, InsertionContent);
END;
result:=true;
end;
begin
end.
It is always a beta version so your tests and critics are welcome.
--
A.G.
Technical Details
Message-ID:
<3f03353e$0$5400$626a54ce@news.free.fr>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!news5.aus1.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!nntp1.fuse.net!proxad.net!feeder2-1.proxad.net!news3-2.free.fr!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <3f03353e$0$5400$626a54ce@news.free.fr>
Subject: [Dialog] Customising Posts
Date: Wed, 2 Jul 2003 21:40:37 +0200
From: Alain GUERIN <news40@spamout-alain-guerin.com.invalid>
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!news5.aus1.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!nntp1.fuse.net!proxad.net!feeder2-1.proxad.net!news3-2.free.fr!not-for-mail
Newsgroups: news.software.readers
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 8bit
Reply-To: news40@alain-guerin.com
Organization: NA
X-Face: GOI#J$,onz-'Uz6us^h!d&!=/wSO@@FxWc?}1i_p@/E%ViONg.TD9>V7VA4(S/j%&mb%4uD
,=8(bmy`{t`AM[~^Y#8*]ZJ;
{y2%EU,B'%$9[qEDa)B{/P4+eTD5E4{Un+XE$|RWd(=aNN%(,yP,cG
=k=7dqQ"euLbBTVKLCV-Ql@aFEdzF1F6GU4b}qG%JPDjL'~T2;
-03s=7s5[QUH@>GQ!CLJ@S{%K[m1
$j`EsD+M&'5>>&-'tfiB0p',<4e0SN,4NDZ:f._qI9vVW0[r\~yk7{.GmY^cN*&/=5qjcH&Q; $
User-Agent: 40tude_Dialog/2.0.5.1
Lines: 180
NNTP-Posting-Date: 02 Jul 2003 21:40:46 MEST
NNTP-Posting-Host: 81.57.20.30
X-Trace: 1057174846 news3-2.free.fr 5400 81.57.20.30:1859
X-Complaints-To: abuse@proxad.net