Article View: news.software.readers
Article #261691Re: Request help with 40tude dialog program syntax
From: Stijn De Jong
Date: Mon, 09 Jan 2017 01:31
Date: Mon, 09 Jan 2017 01:31
426 lines
19606 bytes
19606 bytes
On Sun, 8 Jan 2017 22:15:35 +0100, you wrote:
> Line wrap can be prevented in Dialog by adding a wrap-override character
> via menu <Special><Insert Wrap override character> as first character of
> each line. (Or for a whole block of selected text.) These characters will
> not be transmitted. But they tell Dialog to exclude the marked lines from
> automatic line wraps. (Useful not only for source code with long lines,
> but also for long URL strings.)
I am attempting that suggestion in this post.
Compose: Special > Insert Wrap override character
// JJAddAndRemoveHeadersWhileCheckingNewsgroupsIdentitiesAndServers
// version 1.01 January 9th 2017 "http://pastebin.com/A4Aq0T6T"
// version 1.00 January 8th 2017 "http://pastebin.com/6Md5m67X"
// version 0.02 "http://pastebin.com/sgVDqcqu"
// version 0.01 "http://pastebin.com/2tMYRKM4
// version 0.00 From: JJ <jj4public@vfemail.net>
// Newsgroups: news.software.readers,alt.windows7.general
// Subject: Re: Request help with 40tude dialog program syntax
// Date: Thu, 5 Jan 2017 23:06:19 +0700
// Message-ID: <7vpx5y09pu98.1sukl5d600sda$.dlg@40tude.net>
// Original code for just checking identity, ng, & servers:
// http://dialog.datalist.org/scripts/CheckingIdentity.html
// Original code for just removing headers:
// http://dialog.datalist.org/scripts/RemoveHeaders.html
// Library of 40Tude-Dialog scripts:
// http://dialog.datalist.org/scripts/script_library.html
// This script below will add & remove headers based on a decision tree.
// It will also check for mistakes between business & personal use.
// The decision tree is up to you where working examples are provided.
// DOCUMENTATION:
// The scripting language used by Dialog is Delphi which is based on the
// Pascal programming language. You can use Free Pascal Compiler (FPC)
// documentations if you have any interest on understanding the Pascal
// programming language. You can also ask Pascal/Delphi related question to
// comp.lang.pascal.delphi.misc.
// OPTIONS: Search for "CUSTOMIZATION:"
// 1. Set the "ForNewsgroup" Boolean as desired (search for "ForNewsgroup :")
// Generic default is: true
// 2. Set the "ForEmail" Boolean as desired (search for "ForEmail :")
// Generic default is: false
// 3. Change identity(ies) as desired (search for "from,")
// Generic defaults are set to: id1, id2, id3, id4, & id5
// A sample value is: Kilroy <kilroy@example.com>
// 4. Change newsgroup(s) as desired (search for "newsgroup,")
// Generic defaults are set to: ng1, ng2, ng3, ng4, & ng5
// A sample value is: news.software.readers
// 5. Change server(s) as desired (search for "server,")
// Generic defaults are set to: server1, server2, server3, server4, server5
// A sample value is: Aioe (it should be whatever you've named it)
// 6. Change remove header(s) as desired (search for "Remove_Headers :")
// Generic defaults are set to remove no headers.
// Generic defaults are set to remove the 6 most common headers.
// A sample value is: Remove_Headers := 'User-Agent: '
// 7. Change add header(s) as desired (search for "Add_Headers :")
// Generic defaults are set to add back no headers.
// A sample value is Add_Headers := 'User-Agent: 40tude_Dialog/2.0.15.84'#13#10;
// 8. Modify the if-then-else program control as needed.
// Generic defaults are simply examples of your desired decision tree.
// NOTES:
// If you set Remove_Header to nothing, then none will be removed.
// If you set Add_Header to nothing, then none will be added.
// For some headers you have to remove them first, then add them back.
// Dialog will error when sending if you add headers sans (CR+LF) syntax!
// The original StrMatch fct is case sensitive & matches only the 1st item found!
// Instead, we define a StrContains fct to match multiple either/or newsgroups.
// End of initial comments
program OnBeforeSendingMessage;
(*
Format for Remove_Headers: {} = required, [] = optional
{HeaderName: }[,HeaderName: ][,HeaderName: ][...]
Examples:
- Single header: 'User-Agent: '
- Multiple headers: 'User-Agent: ,X-Face: '
*)
// The user is not expected to need to customize "RemoveHeaders()".
procedure RemoveHeaders(Message : TStringlist;
const Remove_Headers: String
);
var i : integer;
k : integer;
s : string;
CommaPos : integer;
DelHeader : TStringlist;
RemoveH : String;
begin
RemoveH := Remove_Headers;
i := 0;
If ( RemoveH <> '' ) then begin
try
DelHeader := TStringlist.Create;
if ansipos ( ',', RemoveH) = 0 then begin
DelHeader.Add ( LowerCase ( TrimLeft( RemoveH )));
end // if
else begin
CommaPos := 0;
for k := 1 to length ( RemoveH ) do begin
If RemoveH[k] = ',' then begin
DelHeader.Add ( LowerCase ( TrimLeft (copy ( RemoveH, CommaPos + 1, k - ( CommaPos + 1 )))));
CommaPos := k;
end; // if
if k = length ( RemoveH ) then
DelHeader.Add ( LowerCase ( TrimLeft (copy ( RemoveH, CommaPos + 1, k - CommaPos ))));
end; // for
end; // else
s:= Message.text;
while (Message.Strings[i]<>'') do begin
k := 0;
while k <= ( DelHeader.Count - 1 ) do begin
if pos( DelHeader[k], LowerCase ( Message.Strings[i] )) = 1 then
begin
delete ( s, pos(DelHeader[k], LowerCase (s) ), length (Message.Strings[i] ) + 2 );
i := i - 1;
k := DelHeader.Count - 1;
message.text := s;
end; // if
k := k + 1;
end; // while
i := i + 1;
end; //while
message.text:=s;
finally
DelHeader.Free;
end; // try - finally
end; // if
end; // RemoveHeaders
(*
Format for Add_Headers: {} = required, [] = optional
{HeaderName: HeaderValue{#13#10}}[HeaderName: HeaderValue{#13#10}][...]
Examples: (each header must end with CR+LF)
- Single header: 'User-Agent: '#13#10
- Multiple headers: 'User-Agent: MyNewsClient'#13#10'X-Comment: To be, or not to be'#13#10
WARNING: For the Add_Header, you MUST add the pound13-Pound10 as shown in the examples!
If you forget to add the #13#10, then Dialog will error when you send news saying something like:
Posting article failed: 437 Space before colon in "On Fri, 6 Jan 2017" header;
*)
// The user is not expected to need to customize "AddHeaders()".
procedure AddHeaders(var Message : TStringlist;
const Add_Headers: String
);
var
SeparatorIndex: integer;
s: string;
begin
s:= Message.Text;
// writetolog('***before***'#13#10+s, 7);
SeparatorIndex:= pos(#13#10#13#10, s);
Insert(Add_Headers, s, SeparatorIndex+2);
Message.Text:= s;
// writetolog('***after***'#13#10+s, 7);
end;
// The user is not expected to need to customize "StrMatch()".
// WARNING: The StrMatch function can only check the first listed newsgroup!
// Define a StrContains function if you want to match either/or newsgroups!
// function StrContains(const Str: string; const Pattern: string): boolean;
// begin
// result:= pos(Pattern, Str) > 0;
// end;
// These will return `true`:
// StrMatch('abc', 'abc') //"abc" is at start of "abc"
// StrMatch('abc', 'ab') //"ab" is at start of "abc"
// StrMatch('abc', 'a') //"a" is at start of "abc"
// These will return `false`:
// StrMatch('abc', 'abcd') //"abcd" is not at start of "abc"
// StrMatch('abc', 'bc') //"bc" is not at start of "abc"
// StrMatch('abc', 'b') //"b" is not at start of "abc"
// StrMatch('abc', 'c') //"c" is not at start of "abc"
// EXAMPLE: This StrMatch will only match if either n.s.r or a.f.n is the *first* ng in the Newsgroups header:
// if (StrMatch (newsgroup, 'news.software.readers') or StrMatch(newsgroup, 'alt.free.newsservers')) then result := 'id1'
// If defined, this StrContains will match either newsgroup or both in the outgoing Newsgroup header:
// if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.free.newssservers') then result := 'id1'
// End of comments
function StrMatch(str: String; pattern: String):Boolean;
var
patternSize : Integer;
subStr : String;
compareRes : Integer;
begin
patternSize := Length(pattern);
subStr := Copy(str, 1, patternSize);
compareRes := CompareStr(pattern, subStr);
if (compareRes = 0) then
result := true
else
result := false;
end;
// CUSTOMIZATION: identity id1, id2, etc.
// The user is expected to modify to their own identity(ies) below.
//the xxx2Identity() functions must return an empty string if specified string is not identified
// This is probably case sensitive!
function From2Identity(from: String): String;
begin
if (StrMatch(from, 'First1 Last1 <email1@domain.com>')) then
result := 'id1'
else if (StrMatch(from, 'First2 Last2 <email2@domain.com>')) then
result := 'id2'
else if (StrMatch(from, 'First3 Last3 <email3@domain.com>')) then
result := 'id3'
else if (StrMatch(from, 'First4 Last4 <email4@domain.com>')) then
result := 'id4'
else if (StrMatch(from, 'First5 Last5 <email5@domain.com>')) then
result := 'id5'
else if (StrMatch(from, 'First6 Last6 <email6@domain.com>')) then
result := 'id6'
else
result := '';
end;
// The user is not expected to need to customize "StrContains()".
function StrContains(const Str: string; const Pattern: string): boolean;
begin
result:= pos(Pattern, Str) > 0;
end;
// CUSTOMIZATION: newsgroups ng1, ng2, etc.
// The user is expected to modify to their own newsgroup(s) below.
function NewsGroup2Identity(newsgroup: String): String;
begin
if StrContains(newsgroup, 'ng1') or StrContains(newsgroup, 'ng2') then
result := 'id1'
else if StrContains(newsgroup, 'ng3') then
result := 'id2'
else if StrContains(newsgroup, 'ng4') then
result := 'id3'
else
result := '';
end;
// CUSTOMIZATION: servers server1, server2, etc.
// The user is expected to modify to their own server(s) below.
// The name of the server is what Dialog lists in the "Available Servers" GUI
function Server2Identity(server: String): String;
begin
if (CompareStr(server, 'server1') = 0) then
result := 'id1'
else if (CompareStr(server, 'server2') = 0) then
result := 'id2'
else
result := '';
end;
// The user is not expected to need to customize "GetIdentities()".
procedure GetIdentities(var message: TStringlist; servername: string;
isEmail: boolean; var FromIdentity: String; var NewsgroupIdentity: String;
var ServerIdentity: String);
var i : Integer;
begin
FromIdentity := '';
NewsgroupIdentity := '';
ServerIdentity := '';
if (not IsEmail) then
begin
for i := 0 to Message.Count - 1 do
begin
if (strMatch(Message[i], 'From:')) then
fromIdentity := Copy(Message[i], 7, Length(Message[i]) - 6);
if (strMatch(Message[i], 'Newsgroups:')) then
newsgroupIdentity := Copy(Message[i], 13, Length(Message[i]) - 12);
end;
fromIdentity := From2Identity(fromIdentity);
newsgroupIdentity := NewsGroup2Identity(newsgroupIdentity);
serverIdentity := Server2Identity(servername);
// The default log file is C:/Program Files/40tude/logs/YYYYMMDD.log
WriteToLog(' fromIdentity = ' + fromIdentity, 7);
WriteToLog(' newsgroupIdentity = ' + newsgroupIdentity, 7);
WriteToLog(' serverIdentity = ' + serverIdentity, 7);
end;
end;
// The user is not expected to need to customize "LogHeaders()".
procedure LogHeaders(var Message: TStringlist);
var
i: integer;
s: string;
begin
s:= '';
for i:= 0 to message.count-1 do
begin
if message[i] <> '' then s:= s+message[i]+#13#10
else break;
end;
writetolog(s, 7);
end;
function OnBeforeSendingMessage(var Message : TStringlist;
Servername : string;
IsEmail : boolean
):boolean;
var
ForEmail: boolean;
ForNewsgroup : boolean;
FromIdentity: String;
NewsgroupIdentity: String;
ServerIdentity: String;
Remove_Headers: String;
Add_Headers: String;
begin
// CUSTOMIZATION: main decision tree
// The user is expected to wish to customize this main decision tree.
//get the identities of the message
GetIdentities(message, servername, true, FromIdentity, NewsgroupIdentity, ServerIdentity);
// Four program decisions to be made if you wish to change the program defaults:
// 1. This Boolean sets whether email headers are modified:
// ForEmail := false; //false means don't do email message by default
// ForEmail := true; //true means do email headers
// 2. This Boolean sets whether newsgroup headers are modified:
// ForNewsgroup := false; //false means don't do newsgroup message by default
// ForNewsgroup := true; //true means do newsgroup messages
// 3. This string syntax sets the default headers to remove (if not redefined):
// Remove_Headers := ''; //null means don't remove any header by default
// Remove_Headers := 'User-Agent: ,Message-ID: '; //string means remove these headers
// 4. This string syntax sets the default headers to add (if not redefined):
// Add_Headers := ''; //null means don't add any header by default
// Add_Headers := 'X-Comment: John Doe was here'; //string means add these header strings
// NOTE: By default, 40Tude-Dialog generates a dialog-specific message id.
// You can turn off this message-id autogeneration in the Dialog GUI.
// Or you can remove that message-id after the fact in this script.
// NOTE: By default, 40Tude-Dialog sends the system date to the news server.
// The news server will use that system date in the Date: header.
// The news server will generate a GMT date if there is no Date: header.
//
// DEFAULT SETTINGS:
ForEmail := false; //false means don't do email message by default
ForNewsgroup := true; //true means do newsgroup messages
Remove_Headers := ''; //null means don't remove any header by default
Add_Headers := ''; //null means don't add any header by default
{The main decision.
For FromIdentity, comparison must match against string returned by From2Identity() function.
Same applies to NewsgroupIdentity and ServerIdentity.
Note that identities may be an empty string.
Set Remove_Header to remove header(s).
Set Add_Header to add header(s).
Set ForEmail and/or ForNewsgroup to `true` to add/remove header for email/newsgroup messages.
}
// EXAMPLES:
// Remove_Headers = 'User-Agent: ';
// Remove_Headers = 'X-Newsreader: ,X-Scoring: ';
// Remove_Headers := 'Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: ';
//
// Add_Headers := 'User-Agent: 40tude_Dialog/2.0.15.84'#13#10;
// Add_Headers := 'Organization: none'#13#10 + 'X-Comment: As always, YMMV'#13#10;
// Add_Headers := 'Mime-Version: 1.0'#13#10 + 'Content-Type: text/plain; charset="US-ASCII"'#13#10 + 'Content-Transfer-Encoding: 7bit'#13#10;
// NOTES:
// You can't set some headers that the server wants to set (e.g., NNTP-Posting-HOST).
// If nothing is specified NNTP defaults to 'Content-Type: text/plain; charset=US-ASCII' + 'Content-Transfer-Encoding: 7bit'.
//
if FromIdentity = 'id1' then
begin
ForNewsgroup := true;
Remove_Headers = 'User-Agent: ';
Add_Headers := 'User-Agent: 40tude_Dialog/2.0.15.84'#13#10;
end // id1
else
if (FromIdentity = 'id2') and (NewsgroupIdentity = 'id2') then
begin
ForNewsgroup := true;
Remove_Headers = 'X-Newsreader: ,X-Scoring: ';
Add_Headers := 'Organization: none'#13#10 + 'X-Comment: As always, YMMV'#13#10;
end // id2
else
if (FromIdentity = 'id3') and (NewsgroupIdentity = 'id3') and (Server = 'id3') then
begin
ForEmail := false;
ForNewsgroup := true;
Remove_Headers := 'Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: ';
Add_Headers := 'Mime-Version: 1.0'#13#10 + 'Content-Type: text/plain; charset="US-ASCII"'#13#10 + 'Content-Transfer-Encoding: 7bit'#13#10;
end // id3
else
if (FromIdentity = 'id4') and (NewsgroupIdentity = 'id3') then
begin
ForNewsgroup := true;
Remove_Headers := ''; //null means don't remove any header by default
Add_Headers := ''; //null means don't add any header by default
end // id4
else
if (FromIdentity = 'id5') and (NewsgroupIdentity = 'id4') and (ServerIdentity = 'id3') then
begin
ForNewsgroup := true;
// If you don't have a Remove_Headers line, then it will use the default.
// If you don't have an Add_Headers line, then it will use the default.
end // id5
else
if (FromIdentity = 'id6') and (ServerIdentity = 'id1') then
begin
ForNewsgroup := true;
Remove_Headers := 'User-Agent: ,Message-ID: ,Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: ';
Add_Headers := 'User-Agent: 40tude_Dialog/2.0.15.41'#13#10 + 'Content-Type: text/plain; charset="US-ASCII"'#13#10 + 'Content-Transfer-Encoding: 7bit'#13#10;
end; // id6
if (IsEmail and ForEmail) or ((not IsEmail) and ForNewsgroup) then
begin
if Remove_Headers <> '' then RemoveHeaders(Message, Remove_Headers);
if Add_Headers <> '' then AddHeaders(Message, Add_Headers);
end;
result := true;
// result := false; //uncomment this line for testing purposes (doesn't send the message)
end;
// ----------------------------------------------------------------------
begin
end.
Technical Details
Message-ID:
<o4up56$1bpe$1@gioia.aioe.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.(126883).mbox.7z!not-for-mailReferences:
<o491jh$7jr$1@gioia.aioe.org> <o4926s$933$1@gioia.aioe.org> <o492qg$a9k$1@gioia.aioe.org> <1ibo1gzmbqy5b.33119bupvh2q.dlg@40tude.net> <o4h57j$hhe$6@news.mixmin.net> <o4jr33$u80$1@news.mixmin.net> <7vpx5y09pu98.1sukl5d600sda$.dlg@40tude.net> <o4mllr$1tes$1@gioia.aioe.org> <o4mmls$1ufs$1@gioia.aioe.org> <o4mp2u$1mp$1@gioia.aioe.org> <o4mqdl$3dn$1@gioia.aioe.org> <18a15xlqpx8bu$.p7s6f5qnpimv$.dlg@40tude.net> <o4p63d$1jiv$1@gioia.aioe.org> <2nmhjmd7yn5z.7aee9qvl2s4h.dlg@40tude.net> <o4rrp6$1uh9$1@gioia.aioe.org> <o4s14o$80h$1@gioia.aioe.org> <raqqb2wh4vt$.1osst5ylm2z2k$.dlg@40tude.net> <kfn5rah4qizt$.dlg@b.rose.tmpbox.news.arcor.de>Show Full Headers
Complete Article Headers
Message-ID: <o4up56$1bpe$1@gioia.aioe.org> Subject: Re: Request help with 40tude dialog program syntax Date: Mon, 09 Jan 2017 01:31:20 +0000 From: Stijn De Jong <stijndekoning@nlnet.nl> References: <o491jh$7jr$1@gioia.aioe.org> <o4926s$933$1@gioia.aioe.org> <o492qg$a9k$1@gioia.aioe.org> <1ibo1gzmbqy5b.33119bupvh2q.dlg@40tude.net> <o4h57j$hhe$6@news.mixmin.net> <o4jr33$u80$1@news.mixmin.net> <7vpx5y09pu98.1sukl5d600sda$.dlg@40tude.net> <o4mllr$1tes$1@gioia.aioe.org> <o4mmls$1ufs$1@gioia.aioe.org> <o4mp2u$1mp$1@gioia.aioe.org> <o4mqdl$3dn$1@gioia.aioe.org> <18a15xlqpx8bu$.p7s6f5qnpimv$.dlg@40tude.net> <o4p63d$1jiv$1@gioia.aioe.org> <2nmhjmd7yn5z.7aee9qvl2s4h.dlg@40tude.net> <o4rrp6$1uh9$1@gioia.aioe.org> <o4s14o$80h$1@gioia.aioe.org> <raqqb2wh4vt$.1osst5ylm2z2k$.dlg@40tude.net> <kfn5rah4qizt$.dlg@b.rose.tmpbox.news.arcor.de> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.(126883).mbox.7z!not-for-mail Newsgroups: news.software.readers Organization: Aioe.org NNTP Server Lines: 426 NNTP-Posting-Host: hfOAoZlqGeFs4SUbLxBJ8Q.user.gioia.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Received-Body-CRC: 3463910728 X-Received-Bytes: 19564