On Sat, 7 Jan 2017 00:34:06 +0100, you wrote:
> I don't know, whether this was good for you (and for JJ, FWIW)... Changing
> just a few settings will not teach you the necessary skills to adjust the
> script (or write others), if need be. Therefore, you'll continue to depend
> on JJ or others for explanations, adjustments, and so on. And other people
> with /seemingly/ comparable needs may try to use the script, as well. (With
> maybe even less knowledge about the inner workings, suitable settings, and
> so on.)
JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNgAndServers
http://pastebin.com/sgVDqcqu
I can't possibly NOT understand what you're trying to say, which is that I
would be better served (from a programming standpoint) if I programmed the
code myself, instead of relying on JJ's rewrite of the code.
I think you're thinking exactly like expert programmers would think.
So, from an expert programmer's perspective, your thinking is apropos.
However, from a novice's perspective, the tradeoff of learning Dialog from
scratch to just the job done is a completely different equation.
In fact, I had already given up on Dialog scripting (and said so), BEFORE
JJ posted his modified script on pastebin.
Even after JJ posted his first version, when I tested it, it didn't work.
So JJ fixed it, and when I tested that, it worked but had a problem with
multiple newsgroups.
Then when JJ fixed that, we had a really good set of working code that many
others could use out of the box.
We got something done with Dialog.
And, we improved the code base for Dialog, so others can use it themselves.
So the real tradeoff was between:
a. Giving up on getting Dialog to do anything, or,
b. Using JJ's script (testing it, tweaking it, & re-publishing it).
Having said that, I understand your point of view which is that I was a
cripple before I opened this thread, and I'm still a cripple after JJ
provided the solution.
That's true.
But, I was never going to learn Dialog, so it was a choice really between
getting nothing done versus getting the job done.
From THAT perspective, JJ and I and you worked together.
The bonus is that millions of others (OK, maybe tens? or maybe hundreds?)
will benefit from the latest revised code, which I posted here earlier
today:
JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNgAndServers
http://pastebin.com/sgVDqcqu
> Because OnBeforeSendingMessage is probably the most dangerous place for
> scripted alterations inside Dialog, publishing ready-to-use script code
> carries a considerable burden: It has to be written as failsafe as
> possible and should take not only simple usage cases, but also "obscure"
> languages, special characters, encoded attachments, header-like text in
> the body, use of fixed field substrings inside search/replace terms,...
> into account.
I can't possibly disagree with anything you wrote, but I will point out
that again you're speaking from an expert programmer's perspective, and not
from the perspective of someone just wanting to get Dialog to do something.
In fact, while everything you said is appropriate, very few people actually
do what you said for the Dialog scripts. I know this because I have tried
to get Dialog sripts to work where I ran into EXACTLY the issues you speak
of. In fact, MOST of the Dialog scripts I tried from the official site
failed in my tests.
For example, there were multiple Remove Header scripts, where the one I
chose was the ONLY one that worked for me in the first pass, and, even
then, it didn't have a decent example list of syntax for more than one
header (nor for the list of the 6 allowable headers that could be removed).
So I've personally experienced exactly that which you say shouldn't happen,
and, while I can't disagree with you that it shouldn't happen, the
alternative is to get nothing done on Dialog.
I think posting the script (as I do below), has more value to others than
to hold it tightly to my chest simply because it's not well tested in a
variety of circumstances. If it works for just half the people who use it,
then it would have served its purpose well.
At the very worst, we added dozens of comments that the original code never
had, so we left much less up for others to have to figure out on their own.
Here is the latest code (but the text may get messed up by newsreaders
JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNgAndServers
http://pastebin.com/sgVDqcqu
====================== cut here =================
// JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNgAndServers
// <
http://pastebin.com/fcYjL9Vb> newer version
// <
http://pastebin.com/2tMYRKM4> older version
// NOTES:
// The StrMatch fct is case sensitive and only matches the first item
found!
// Define a StrContains fct to match multiple either/or newsgroups.
// If you don't set Remove_Header, then none will be removed.
// If you don't set Add_Header, 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!
// WriteLn doesn't seem to do anything.
// CUSTOMIZATION ORDER OF OPERATIONS:
// 1. Set the "ForNewsgroup" Boolean as desired (search for "ForNewsgroup
:")
// 2. Set the "ForEmail" Boolean as desired (search for "ForEmail :")
// 3. Change identity(ies) as desired (search for "from,")
// 4. Change newsgroup(s) as desired (search for "newsgroup,")
// 5. Change server(s) as desired (search for "server,")
// 6. Change remove header(s) as desired (search for "Remove_Headers :")
// 7. Change add header(s) as desired (search for "Add_Headers :")
// End of initial comments.
// Customize your identity below for personal or business use as needed.
// The string match is probably case sensitive!
function From2Identity(from: String): String;
begin
if (StrMatch(from, 'First1 Last1 <
ema...@domain.net>')) then
result := 'id1'
else if (StrMatch(from, 'First2 Last2 <
ema...@domain.net>')) then
result := 'id2'
else if (StrMatch(from, 'First3 Last3 <
ema...@domain.net>')) then
result := 'id3'
else
result := '';
end;
// 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;
// EXAMPLE: This StrMatch will only match the first newsgroup in the
outgoing Newsgroup 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 StrContains(const Str: string; const Pattern: string): boolean;
begin
result:= pos(Pattern, Str) > 0;
end;
function NewsGroup2Identity(newsgroup: String): String;
begin
if StrContains(newsgroup, 'ng1') or StrContains(newsgroup, 'ng2') then
result := 'id1'
else if StrMatch(newsgroup, 'ng3') then
result := 'id2'
else if StrMatch(newsgroup, 'ng4') then
result := 'id3'
else
result := '';
end;
// The name of the server is what Dialog lists in the "Available Servers"
UI.
function Server2Identity(server: String): String;
begin
if (CompareStr(server, 'aioe_119') = 0) then
result := 'id1'
else if (CompareStr(server, 'albasani_563') = 0) then
// The default log file is C:/Program Files/40tude/logs/YYYYMMDD.log
ForNewsgroup := true; //true means do newsgroup messages
Remove_Headers := ''; //null means don't remove any header by default
Remove_Headers := 'User-Agent: ,Message-ID: ,Date: '; //remove these
outgoing headers
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: ,Message-ID: ,Date: ,Mime-Version:
,Content-Type: ,Content-Transfer-Encoding: ';
// Add_Headers := 'Organization: none whatsoever'#13#10;
// Add_Headers := 'X-Comment: Jane Doe was here'#13#10 + 'X-Greeting: Hello
there!'#13#10;
// Note that some headers cannot be set (for example, NNTP Posting Host or
Newsgroups)
//
if FromIdentity = 'id1' then
begin
ForNewsgroup := true;
Remove_Headers := 'User-Agent: ,Message-ID: ';
// Add_Headers := 'X-Comment: Jane Doe was here'#13#10 + 'X-Greeting:
Hello there!'#13#10;
end
else if (FromIdentity = 'id2') and (NewsgroupIdentity = 'id2') then
begin
ForNewsgroup := true;
// Remove_Headers := 'User-Agent: ,Content-Transfer-Encoding: '
Add_Headers := 'Organization: none whatsoever'#13#10;
end
else if (FromIdentity = 'id3') and (ServerIdentity = 'id1') then
begin // id3
ForEmail := true;
ForNewsgroup := true;
Remove_Headers := 'User-Agent: ,Mime-Version: ';
Add_Headers := 'User-Agent: My user agent is 40Tude Dialog on Windows
10'#13#10;
// WriteLn(Remove_Headers); // This WriteLn command does not seem to do
anything.
// WriteLn(Add_Headers); // This WriteLn command does not seem to do
anything.
end; // id3
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.
====================== cut here =================