If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Rate Thread | Display Modes |
#31
|
|||
|
|||
Request help with 40tude dialog program syntax
Op Tue, 3 Jan 2017 22:31:24 +0100, Stijn De Jong schreef:
Please use below modified script. http://pastebin.com/9kBWDbU8 I've added some comments for reference. test... Thank you for that modified script, where I see that you left everything as it was and changed the part that needed to be changed, which was the way that the headers were defined for business versus for personal posts and emails. Your script has no syntax errors and therefore I've been testing it but I haven't gotten it to actually work yet (which is why I haven't reported back until now because I was hoping to report a success). The great thing is that the decision to have personal or business headers seems to be syntactically safe inside an ifthenelse. But the bad news (so far) is that it doesn't do what it's supposed to do. However, the original question was about the syntax for setting the header variable so now the problem is mine because it's about the program flow. Since the hope is that others can also use this program, I do suggest that anyone using the wonderful program you provided add something like the following to the header comments. // Source code: "http://pastebin.com/9kBWDbU8" // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Tue, 3 Jan 2017 23:07:15 +0700 // Message-ID: // ACTION: // 1. Change identity as needed (search for "from,") // 2. Change newsgroup as needed (search for "newsgroup,") // 3. Change server as needed (search for "server,") // 4. Change header as needed (search for "Remove_Headers :" |
Ads |
#32
|
|||
|
|||
Request help with 40tude dialog program syntax
On Wed, 4 Jan 2017 21:56:52 -0000 (UTC), Stijn De Jong wrote:
Thank you for that modified script, where I see that you left everything as it was and changed the part that needed to be changed, which was the way that the headers were defined for business versus for personal posts and emails. Your script has no syntax errors and therefore I've been testing it but I haven't gotten it to actually work yet (which is why I haven't reported back until now because I was hoping to report a success). The great thing is that the decision to have personal or business headers seems to be syntactically safe inside an ifthenelse. But the bad news (so far) is that it doesn't do what it's supposed to do. However, the original question was about the syntax for setting the header variable so now the problem is mine because it's about the program flow. Since the hope is that others can also use this program, I do suggest that anyone using the wonderful program you provided add something like the following to the header comments. // Source code: "http://pastebin.com/9kBWDbU8" // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Tue, 3 Jan 2017 23:07:15 +0700 // Message-ID: // ACTION: // 1. Change identity as needed (search for "from,") // 2. Change newsgroup as needed (search for "newsgroup,") // 3. Change server as needed (search for "server,") // 4. Change header as needed (search for "Remove_Headers :" Sorry. There was an error in the previous script. Please use this one. This time, I've tested it thoroughly. http://pastebin.com/2tMYRKM4 I've changed it to include the ability to add new headers, and made it so that any identity may be empty. It'll be up to the main decision code to check each identity. Note that the string format for `Add_Headers` is different from `Remove_Headers` (see `AddHeader()` function comments and the example in the main decision code). I've also added to more variables `ForEmail` and `ForNewsgroup` to indicate which type of message should be processed so that it's more flexible. Both can be `true` to add/remove headers on both message types. But both must not be `false`, otherwise nothing will be processed. The `RemoveHeaders()` function was changed for this purpose. Since headers removal is performed first, then the headers insertion, you can use both `Remove_Headers` and `Add_Headers` to change any existing header. i.e. add if not exist, or change it if one exist. e.g. Remove_Headers:= 'User-Agent: '; Add_Headers:= 'User-Agent: Thunderbird 2086 (Windows 3000; NT9.0)'#13#10; |
#33
|
|||
|
|||
Request help with 40tude dialog program syntax
Sorry. There was an error in the previous script. Please use this one. This
time, I've tested it thoroughly. http://pastebin.com/2tMYRKM4 Thanks for sticking with us, as I think it would be generally useful to others also to have a different set of headers and cross checks based on personal versus work posts and emails (for example to be able to avoid posting to work newsgroups using the personal login and vice versa, to avoid using business servers for personal posts). As soon as I saw your post, I picked up: http://pastebin.com/raw/2tMYRKM4 and saved it to disk using control+a control+c so that all the syntax is preserved and I added the following comments in the header. // JJ_add_and_remove_headers_while_doublechecking_ide ntity_ng_and_servers // http://pastebin.com/2tMYRKM4 // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Thu, 5 Jan 2017 23:06:19 +0700 // Message-ID: // Original code for checking identity: // http://dialog.datalist.org/scripts/C...gIdentity.html // Original code for modifying headers: // http://dialog.datalist.org/scripts/RemoveHeaders.html // ACTION: // 1. Change identity as needed (search for "from,") // 2. Change newsgroup as needed (search for "newsgroup,") // 3. Change server as needed (search for "server,") // 4. Change remove header as needed (search for "Remove_Headers :") // 5. Change add header as needed (search for "Add_Headers :") The only thing I changed was that I added the syntax to add an "or" condition to the string match of the newsgroup lines (so that people have a ready-made template for changing the list of newsgroups syntactically): FROM: if StrMatch(newsgroup, 'news.software.readers') then result := 'id1' TO: if StrMatch(newsgroup, 'news.software.readers') or StrMatch(newsgroup, 'alt.windows7.general') then result := 'id1' I've changed it to include the ability to add new headers, I was always planning on doing that so you think similarly to the way I think, which is that personal and business headers can not only be removed, but added. I just didn't know how to do that so I didn't ask that question. Thanks for adding that capability to add headers as needed (which I'll test out subsequently). and made it so that any identity may be empty. I'm not sure what that means that any identity may be empty, but I think what you mean is that the default should be that you shouldn't have to set the identity and if you don't set the identity, then the settings will work for all identities (which is, in effect, how the remove_headers original program worked). Note that the string format for `Add_Headers` is different from `Remove_Headers` (see `AddHeader()` function comments and the example in the main decision code). Thank you for pointing out that the syntax for adding headers is different than the syntax for removing headers. I've also added to more variables `ForEmail` and `ForNewsgroup` to indicate which type of message should be processed so that it's more flexible. Both can be `true` to add/remove headers on both message types. But both must not be `false`, otherwise nothing will be processed. The `RemoveHeaders()` function was changed for this purpose. Thank you for fixing the for-mail and for-news variables, which I think, were each done differently in the two original programs that comprise the bulk of this program. Since headers removal is performed first, then the headers insertion, you can use both `Remove_Headers` and `Add_Headers` to change any existing header. i.e. add if not exist, or change it if one exist. e.g. Remove_Headers:= 'User-Agent: '; Add_Headers:= 'User-Agent: Thunderbird 2086 (Windows 3000; NT9.0)'#13#10; That's a nice program-flow consideration! You can remove a header and then add a different header in its place. I will test this out and let you know how it works. |
#34
|
|||
|
|||
Request help with 40tude dialog program syntax
X-Comment: If this shows up, JJ is a veritable genius!
That Add_Header line worked! FROM: if StrMatch(newsgroup, 'news.software.readers') then result := 'id1' TO: if StrMatch(newsgroup, 'news.software.readers') or StrMatch(newsgroup, 'alt.windows7.general') then result := 'id1' But this had some kind of syntax error so I had to put it back to your original single newsgroup. But to help others with syntax, I need to experiment to see how to fix that so there is at least one example that can handle multiple newsgroups. if (StrMatch(newsgroup, 'ng1') or StrMatch(newsgroup, 'ng2')) Here's a vignette of what I'm using for this post: function NewsGroup2Identity(newsgroup: String): String; // id1 is for news.software.readers,alt.windows7.general //SYNTAX: if (StrMatch(newsgroup, 'ng1') or StrMatch(newsgroup, 'ng2')) // begin if (StrMatch (newsgroup, 'news.software.readers') or StrMatch(newsgroup, 'alt.windows7.general')) then result := 'id1' else if StrMatch(newsgroup, 'alt.free.newsservers') then result := 'id2' else if StrMatch(newsgroup, 'alt.test') then result := 'id3' else result := ''; end; |
#35
|
|||
|
|||
Request help with 40tude dialog program syntax
On Fri, 6 Jan 2017 00:59:55 +0100, you wrote:
But this had some kind of syntax error The script compiles, executes, and saves without error. The only error I'm getting is Dialog is complaining when I actually send the message. Then I get the following error: Posting article failed: 437 Space before colon in "On Fri, 6 Jan 2017" header; I think it may be related to the add header where you warned me to add the CR+LF (aka #13#10) but I didn't initially heed that warning. If you get this, then adding the pount13-pound10 CR+LF worked. if FromIdentity = 'id1' then begin ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Message-ID: '; Add_Headers := 'X-Comment: JJ is a veritable genius!'#13#10; end |
#36
|
|||
|
|||
Request help with 40tude dialog program syntax
On Fri, 6 Jan 2017 00:41:03 +0000 (UTC), you wrote:
If you get this, then adding the pount13-pound10 CR+LF worked. I should never have doubted you JJ! The moment I added back the pound13-pound10, I no longer received that error from Dialog upon sending of "437 space before colon". So that others can get the benefit of JJ's efforts and my added comments, here is the script I just used which worked perfectly: http://pastebin.com/7n6SvGuh The overall goal is to keep personal and business news and/or email separate simply by setting appropriate variables in the script below. Here is that same script pasted into this post, but it might get modified by newsreaders so the pastebin raw source is probably more reliable. All the thanks go to the original authors, and JJ and those who helped in between! This script below is essentially the same as the one you just posted, but with a few more comments and a couple more examples involved (but otherwise the same). // JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNg AndServers // http://pastebin.com/2tMYRKM4 // More comments & examples: http://pastebin.com/7n6SvGuh // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Thu, 5 Jan 2017 23:06:19 +0700 // Message-ID: // Original code for checking identity: // http://dialog.datalist.org/scripts/C...gIdentity.html // Original code for modifying headers: // http://dialog.datalist.org/scripts/RemoveHeaders.html // CUSTOMIZATION: // 1. Set the "ForEmail" Boolean as desired (search for "ForEmail :") // 2. Set the "ForNewsgroup" Boolean as desired (search for "ForNewsgroup :") // 3. Change identity as desired (search for "from,") // 4. If ForNewsgroup is true, change newsgroup as desired (search for "newsgroup,") // 5. Change server as desired (search for "server,") // 6. Change remove header as desired (search for "Remove_Headers :") // 7. Change add header as desired (search for "Add_Headers :") program OnBeforeSendingMessage; (* Format for Remove_Headers: {} = required, [] = optional {HeaderName: }[,HeaderName: ][,HeaderName: ][...] Examples: - Single header: 'User-Agent: ' - Multiple headers: 'User-Agent: ,X-Face: ' *) 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; *) 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; 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; //the xxx2Identity() functions must return an empty string if specified string is not identified function From2Identity(from: String): String; begin if (StrMatch(from, 'First1 Last1 ')) then result := 'id1' else if (StrMatch(from, 'First2 Last2 ')) then result := 'id2' else if (StrMatch(from, 'First3 Last3 ')) then result := 'id3' else result := ''; end; function NewsGroup2Identity(newsgroup: String): String; // news.software.readers,alt.windows7.general //SYNTAX: if (StrMatch(newsgroup, 'ng1') or StrMatch(newsgroup, 'ng2')) then begin if (StrMatch (newsgroup, 'news.software.readers') or StrMatch(newsgroup, 'alt.free.newssservers')) then result := 'id1' else if StrMatch(newsgroup, 'alt.free.newsservers') then result := 'id2' else if StrMatch(newsgroup, 'alt.test') then result := 'id3' else result := ''; end; function Server2Identity(server: String): String; begin if (CompareStr(server, 'aioe_119') = 0) then result := 'id1' else if (CompareStr(server, 'mixmin_563') = 0) then result := 'id2' else result := ''; end; 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 lines below write to the log file of the format ../40tude/logs/20161231.log WriteToLog(' fromIdentity = ' + fromIdentity, 7); WriteToLog(' newsgroupIdentity = ' + newsgroupIdentity, 7); WriteToLog(' serverIdentity = ' + serverIdentity, 7); end; end; 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 //get the identities of the message GetIdentities(message, servername, isEmail, 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 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. } // Remove_Headers := 'User-Agent: ,Message-ID: ,Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: '; if FromIdentity = 'id1' then begin ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Message-ID: '; Remove_Headers := 'User-Agent: ,Message-ID: ,Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: '; Add_Headers := 'X-Comment: JJ is a veritable genius!'#13#10; end else if (FromIdentity = 'id2') and (NewsgroupIdentity = 'id1') then begin ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Content-Transfer-Encoding: ' Add_Headers := 'X-Comment: John Doe was here'#13#10; end else if (FromIdentity = 'id3') and (ServerIdentity = 'id2') then begin ForEmail := true; ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Mime-Version: '; Add_Headers := 'X-Comment: Jane Doe was here'#13#10 + 'X-Greeting: Hello there!'#13#10; end; 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. |
#37
|
|||
|
|||
Request help with 40tude dialog program syntax
Good to know that it works for you.
One thing you should know is that the `StrMatch()` function compares the `Pattern` argument against the start of the `str` argument. So when you use the function to compare the `newsgroup` argument in the `NewsGroup2Identity()` function, and the message was posted to multiple newsgroups, that function can only check the first listed newsgroup. For example, suppose you're using the function like so: if StrMatch(newsgroup, 'news.software.readers') then //... If the contents of the newsgroup variable is: alt.test, news.software.readers Then the above check will never match. For the sake of flexibility, here's a function that work like `StrMatch()` but the pattern can match anywhere in the string being searched. i.e. the pattern can be at start, at middle, or at end. String comparison is case sensitive, just like `StrMatch()` does. function StrContains(const Str: string; const Pattern: string): boolean; begin result:= pos(Pattern, Str) 0; end; Insert it into anywhere in the script outside of any other function and use it just like `StrMatch()`. e.g. if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.windows7.general') then //... |
#38
|
|||
|
|||
Request help with 40tude dialog program syntax
On Fri, 6 Jan 2017 16:57:31 +0700, you wrote:
Good to know that it works for you. Thank you JJ for rewriting the script so that it's useful! You are a great Usenet citizen in that you give back to the group. I realized, in my tests, that there was some funny stuff going on, but I wasn't sure what the funny stuff was. So a few mistakes I made we a. I couldn't get the string match on multiple newsgroups working (Now I know why, based on what you wrote below!) b. I couldn't add certain headers (e.g., NNTP-Posting-Host). (I suspect that's an NNTP RFC spec that prevents that from working) c. I couldn't get a WriteLn(Add_Header) to write to the message window. (The WriteToLog worked but it wrote to the log file instead.) It's clear you tested the script well since your logic is more flexible than the original two scripts were. 1. You placed the remove_headers variable in both a syntactically correct and logically correct location! 2. You added the capability to crosscheck based on any one, two, or three combinations of identity, and/or server, and/or newsgroup. 3. You added the ability to add headers (and you resolved the non-intuitive requirement for pound13-pound10 CR+LF syntax), particularly for multiple headers being added. 4. You added variables so that reasonable defaults exist if someone does not wish to change any of the variables. 5. And you provided useful working syntactical examples, so that noobs (like I am) can more easily intuit settings that are syntactically correct! Overall, your efforts should help anyone, and particularly those who have different requirements for news/email for personal versus business needs. One thing you should know is that the `StrMatch()` function compares the `Pattern` argument against the start of the `str` argument. So when you use the function to compare the `newsgroup` argument in the `NewsGroup2Identity()` function, and the message was posted to multiple newsgroups, that function can only check the first listed newsgroup. Thank you for pointing that out because that string-match was driving me nuts! So are you saying that, functionally, these two command are, in effect, exactly the same functionality? A. if (StrMatch (newsgroup, 'news.software.readers') or StrMatch (newsgroup, 'alt.free.newsservers')) then result := 'id1' B. if StrMatch(newsgroup, 'news.software.readers') then result := 'id1' Is it that both A & B above will only set the result to "id1" if "news.software.readers" is the first newsgroup in the outgoing Newsgroups: header? Asked another way, are you saying that only the first outgoing header line below will be matched by either of the two commands above? Newsgroups: news.software.readers,alt.free.newsservers Newsgroups: alt.free.newsservers,news.software.readers For example, suppose you're using the function like so: if StrMatch(newsgroup, 'news.software.readers') then //... If the contents of the newsgroup variable is: alt.test, news.software.readers Then the above check will never match. I see. You just answered my questions above! Thank you for being clear. I have now modified the comments so that others aren't confused like I was. For the sake of flexibility, here's a function that work like `StrMatch()` but the pattern can match anywhere in the string being searched. i.e. the pattern can be at start, at middle, or at end. String comparison is case sensitive, just like `StrMatch()` does. function StrContains(const Str: string; const Pattern: string): boolean; begin result:= pos(Pattern, Str) 0; end; Insert it into anywhere in the script outside of any other function and use it just like `StrMatch()`. e.g. if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.windows7.general') then //... I just added your new "string contains" function, and a call to it as follows. If this post works, then the vignette below worked. function StrContains(const Str: string; const Pattern: string): boolean; begin result:= pos(Pattern, Str) 0; end; function NewsGroup2Identity(newsgroup: String): String; // 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 // 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 begin if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.free.newssservers') then result := 'id1' else if StrMatch(newsgroup, 'alt.comp.os.windows-10') then result := 'id2' else if StrMatch(newsgroup, 'alt.os.linux') then result := 'id3' else result := ''; end; |
#39
|
|||
|
|||
Request help with 40tude dialog program syntax
On Fri, 6 Jan 2017 22:35:25 +0000 (UTC), you wrote:
I just added your new "string contains" function, and a call to it as follows. If this post works, then the vignette below worked. To give back to everyone for JJ's helpful improvements, here is the newly modified code that worked to send this message and the last message. http://pastebin.com/sgVDqcqu ============ or you can cut here for that code ================= // JJAddAndRemoveHeadersWhileDoubleCheckingIdentityNg AndServers // This script will add & remove headers based on a decision tree. // It will also check for mistakes between business & personal use. // http://pastebin.com/sgVDqcqu (latest revision) // http://pastebin.com/2tMYRKM4 older version // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Thu, 5 Jan 2017 23:06:19 +0700 // Message-ID: // Original code for just checking identity, ng, and servers: // http://dialog.datalist.org/scripts/C...gIdentity.html // Original code for just removing headers: // http://dialog.datalist.org/scripts/RemoveHeaders.html // NOTES: // The StrMatch fct is case sensitive and only matches the 1st 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 "ForNewsgroup" Boolean as desired (search for "ForNewsgroup :") // 2. Set "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. program OnBeforeSendingMessage; (* Format for Remove_Headers: {} = required, [] = optional {HeaderName: }[,HeaderName: ][,HeaderName: ][...] Examples: - Single header: 'User-Agent: ' - Multiple headers: 'User-Agent: ,X-Face: ' *) 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; *) 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; 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; //the xxx2Identity() functions must return an empty string if specified string is not identified // 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 ')) then result := 'id1' else if (StrMatch(from, 'First2 Last2 ')) then result := 'id2' else if (StrMatch(from, 'First3 Last3 ')) 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, 'eternal september') = 0) then result := 'id1' else if (CompareStr(server, 'albasani_119') = 0) then result := 'id2' else result := ''; end; 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; 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 //get the identities of the message GetIdentities(message, servername, isEmail, 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 // 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 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. |
#40
|
|||
|
|||
Request help with 40tude dialog program syntax
On Fri, 6 Jan 2017 22:35:25 +0000 (UTC), Stijn De Jong wrote:
b. I couldn't add certain headers (e.g., NNTP-Posting-Host). (I suspect that's an NNTP RFC spec that prevents that from working) That's correct. The server may also place additional restrictions on which headers and their contents. e.g. the email in the "From" header must match with the email used to register an account from a newsgroups provider. c. I couldn't get a WriteLn(Add_Header) to write to the message window. (The WriteToLog worked but it wrote to the log file instead.) This is a technical problem which is not well explained in Dialog's "Scripting" documentation page. There's a line that says "Only available in script called from the main GUI thread for thread safety" which refers to the `Application`, `Screen`, `Timer1`, and `Timer2` global variables, but actually, the WriteLn() function is one of them too. i.e. they are usable from the main thread, and the OnBeforeSendingMessage, OnBeforeSavingMessage, etc., are executed from a (separate) worker thread, which isn't the main thread. So are you saying that, functionally, these two command are, in effect, exactly the same functionality? A. if (StrMatch (newsgroup, 'news.software.readers') or StrMatch (newsgroup, 'alt.free.newsservers')) then result := 'id1' B. if StrMatch(newsgroup, 'news.software.readers') then result := 'id1' Is it that both A & B above will only set the result to "id1" if "news.software.readers" is the first newsgroup in the outgoing Newsgroups: header? [A] and [b] are different because [A] has two conditions to check, and [b] only has one. [A] will set the result to "id1" if the first newsgroup in the Newsgroups header is "news.software.readers" or "alt.free.newsservers". [b] will set the result to "id1" if the first newsgroup in the Newsgroups header is "news.software.readers". Asked another way, are you saying that only the first outgoing header line below will be matched by either of the two commands above? Newsgroups: news.software.readers,alt.free.newsservers Newsgroups: alt.free.newsservers,news.software.readers [A] will set the result to "id1" for Newsgroups header #1 and #2. First StrMatch() matches header #1, and second StrMatch() matches header#2. [b] will set the result to "id1" for Newsgroups header #1. Here's some simpler examples for the basic of StrMatch(). 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" I just added your new "string contains" function, and a call to it as follows. If this post works, then the vignette below worked. [snip] if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.free.newssservers') then result := 'id1' else if StrMatch(newsgroup, 'alt.comp.os.windows-10') then result := 'id2' else if StrMatch(newsgroup, 'alt.os.linux') then result := 'id3' else result := ''; The first if-then statement (or command) would work as expected, but the second and the third ones may fail if a message is posted to multiple newsgroups because they still use the StrMatch() function. i.e. This won't to set the result to "id2" if the Newsgroups header is "Newsgroups: news.software.readers,alt.comp.os.windows-10". It will only set the result if the header is "Newsgroups: alt.comp.os.windows-10,news.software.readers". //... else if StrMatch(newsgroup, 'alt.comp.os.windows-10') then result := 'id2' //... And this won't to set the result to "id3" if the Newsgroups header is "Newsgroups: alt.comp.os.windows-10,alt.os.linux". It will only set the result if the header is "Newsgroups: alt.os.linux,alt.comp.os.windows-10". //... else if StrMatch(newsgroup, 'alt.os.linux') then result := 'id3' //... PS) 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. |
#41
|
|||
|
|||
Request help with 40tude dialog program syntax
On Sun, 8 Jan 2017 04:00:31 +0700, you wrote:
b. I couldn't add certain headers (e.g., NNTP-Posting-Host). (I suspect that's an NNTP RFC spec that prevents that from working) That's correct. The server may also place additional restrictions on which headers and their contents. e.g. the email in the "From" header must match with the email used to register an account from a newsgroups provider. Thank you JJ for confirming, as anyone who is a noob (like I am) would have similar questions as I have, so, it's great to flesh them out for the deja news record (should others search in the future for this topic). c. I couldn't get a WriteLn(Add_Header) to write to the message window. (The WriteToLog worked but it wrote to the log file instead.) This is a technical problem which is not well explained in Dialog's "Scripting" documentation page. There's a line that says "Only available in script called from the main GUI thread for thread safety" which refers to the `Application`, `Screen`, `Timer1`, and `Timer2` global variables, but actually, the WriteLn() function is one of them too. i.e. they are usable from the main thread, and the OnBeforeSendingMessage, OnBeforeSavingMessage, etc., are executed from a (separate) worker thread, which isn't the main thread. OMG. That's complicated. I think I'll take the simple road, which is to just remove the WriteLn altogether! I just wanted to see what was happening real time without having to dig into the log file. I looked for an option to at least change the location of the log file. http://dialog.datalist.org/faq/frequ...questions.html But I gave up as it doesn't seem to be an option to change the location of the log file, and nobody else seems to have asked that question yet. [A] will set the result to "id1" if the first newsgroup in the Newsgroups header is "news.software.readers" or "alt.free.newsservers". [b] will set the result to "id1" if the first newsgroup in the Newsgroups header is "news.software.readers". Oh. I get it. slaps head It's amazing how you interpret differently what I interpret, but your interpretation makes much more programming sense than does mine! Here's some simpler examples for the basic of StrMatch(). 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" Thanks for those illustrative examples, which make sense. I added them, verbatim, a comments to my version of the code, for future reference. I just added your new "string contains" function, and a call to it as follows. If this post works, then the vignette below worked. [snip] if StrContains(newsgroup, 'news.software.readers') or StrContains(newsgroup, 'alt.free.newssservers') then result := 'id1' else if StrMatch(newsgroup, 'alt.comp.os.windows-10') then result := 'id2' else if StrMatch(newsgroup, 'alt.os.linux') then result := 'id3' else result := ''; The first if-then statement (or command) would work as expected, but the second and the third ones may fail if a message is posted to multiple newsgroups because they still use the StrMatch() function. i.e. Thanks for that clarification and correction that StrMatch is problematic even if it only contains one newsgroup because it depends on the order of the newsgroups in the Newsgroup: header line. I'll modify my version of the code so that it uses StrContains instead of StrMatch (which seems far too limited for this purpose so I wonder why the original contained StrMatch in the first place). 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, 'news.software.readers') or StrContains(newsgroup, 'alt.free.newssservers') then result := 'id1' else if StrContains(newsgroup, 'alt.comp.os.windows-10') then result := 'id2' else if StrContains(newsgroup, 'alt.os.linux') then result := 'id3' else result := ''; end; PS) 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. Thank you for that advice. I've added it as a comment to the code I maintain for future use. |
#42
|
|||
|
|||
Request help with 40tude dialog program syntax
On Sat, 7 Jan 2017 22:57:43 +0000 (UTC), you wrote:
I've added it as a comment to the code I maintain for future use. Here is the latest code with all your comments added, and, with suggestions by Bernd Rose in another thread in the a.s.r newsgroups also added. http://pastebin.com/6Md5m67X ========= obligatory cut here ============ // JJAddAndRemoveHeadersWhileCheckingNewsgroupsIdenti tiesAndServers // version 1.00 January 8th 2017 "http://pastebin.com/6Md5m67X" // version 0.02 "http://pastebin.com/sgVDqcqu" // version 0.01 "http://pastebin.com/2tMYRKM4" // From: JJ // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Thu, 5 Jan 2017 23:06:19 +0700 // Message-ID: // Original code for just checking identity, ng, & servers: // http://dialog.datalist.org/scripts/C...gIdentity.html // Original code for just removing headers: // http://dialog.datalist.org/scripts/RemoveHeaders.html // This script will add & remove headers based on a decision tree. // It will also check for mistakes between business & personal use. // 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. // NOTES: // 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. // CAVEATS: // 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! // CUSTOMIZATION: Search for "CUSTOMIZATION:" // 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 :") // OPTIONS: // If you don't set Remove_Header, then none will be removed. // If you don't set Add_Header, then none will be added. // 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 ')) then result := 'id1' else if (StrMatch(from, 'First2 Last2 ')) then result := 'id2' else if (StrMatch(from, 'First3 Last3 ')) then result := 'id3' 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); // Note that "WriteLn" will never work so don't even think of using it. 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, isEmail, 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 Remove_Headers := 'User-Agent: ,Message-ID: ,Date: '; //remove these outgoing headers 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 := 'Message-ID: ,Date: ,Mime-Version: ,Content-Type: ,Content-Transfer-Encoding: '; // // Add_Headers := 'User-Agent: slrn/1.0.2 (Darwin)'#13#10; // Add_Headers := 'Organization: DNLA GmbH'#13#10; // Add_Headers := 'MIME-Version: 1.0'#13#10 + 'Content-Type: text/plain; charset=UTF-8'#13#10; // if FromIdentity = 'id1' then begin ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Message-ID: '; end // id1 else if (FromIdentity = 'id2') and (NewsgroupIdentity = 'id2') then //else if (FromIdentity = 'id2') then begin ForNewsgroup := true; Remove_Headers := 'User-Agent: ,Content-Transfer-Encoding: ' Add_Headers := 'X-Comment: Caveat emptor!'#13#10; end // id2 else if (FromIdentity = 'id3') and (NewsgroupIdentity = 'id2') and (ServerIdentity = 'id1') then // else if (FromIdentity = 'id3') and (NewsgroupIdentity = 'id3') and (Server = 'id3') then begin ForEmail := true; ForNewsgroup := true; Add_Headers := 'X-Comment: Jane Doe was here'#13#10 + 'X-Greeting: Hello there!'#13#10; 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. ========= obligatory cut here ============ |
#43
|
|||
|
|||
Request help with 40tude dialog program syntax
On Sun, 8 Jan 2017 00:29:20 +0000 (UTC), Stijn De Jong wrote:
GetIdentities(message, servername, isEmail, FromIdentity, NewsgroupIdentity, ServerIdentity); Whoops. That line (at start of OnBeforeSendingMessage) should have been: GetIdentities(message, servername, true, FromIdentity, NewsgroupIdentity, ServerIdentity); i.e. the third parameter should be `true` instead of `isEmail`, so that the function works for both newsgroup and email message. Previously, it won't work if the message being sent is an email. I hope that's the last of my goofs. PS) Please post the script to PasteBin instead of newsgroup, because long lines got broken into separate lines. It can cause syntax error when compiled if the script was copy+pasted from the newsgroup message. |
#44
|
|||
|
|||
Request help with 40tude dialog program syntax
On Sun, 8 Jan 2017 20:32:35 +0700, you wrote:
Whoops. That line (at start of OnBeforeSendingMessage) should have been: GetIdentities(message, servername, true, FromIdentity, NewsgroupIdentity, ServerIdentity); i.e. the third parameter should be `true` instead of `isEmail`, so that the function works for both newsgroup and email message. Previously, it won't work if the message being sent is an email. I hope that's the last of my goofs. PS) Please post the script to PasteBin instead of newsgroup, because long lines got broken into separate lines. It can cause syntax error when compiled if the script was copy+pasted from the newsgroup message. To give back to the ng, here is the update, with many new explanatory comments also added. // JJAddAndRemoveHeadersWhileCheckingNewsgroupsIdenti tiesAndServers // version 1.01 January 9th 2017 "http://pastebin.com/A4Aq0T6T" |
#45
|
|||
|
|||
Request help with 40tude dialog program syntax
On Sun, 8 Jan 2017 22:15:35 +0100, you wrote:
Please post the script to PasteBin instead of newsgroup, because long lines got broken into separate lines. It can cause syntax error when compiled if the script was copy+pasted from the newsgroup message. Line wrap can be prevented in Dialog by adding a wrap-override character via menu SpecialInsert 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.) Depending on the view settings of a receiving client, lines may /appear/ wrongly wrapped, nevertheless. But toggling of "wrapped view" (Ctrlw in Dialog) or copy/paste into the Scripting Editor (or any other editor) should show the long lines unwrapped, again. Bernd I am attempting that suggestion in this post. 40Tude: Compose: Special Insert Wrap override character // JJAddAndRemoveHeadersWhileCheckingNewsgroupsIdenti tiesAndServers // 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 // Newsgroups: news.software.readers,alt.windows7.general // Subject: Request help with 40tude dialog program syntax // Date: Thu, 5 Jan 2017 23:06:19 +0700 // Message-ID: // Original code for just checking identity, ng, & servers: // http://dialog.datalist.org/scripts/C...gIdentity.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 // 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 ')) then result := 'id1' else if (StrMatch(from, 'First2 Last2 ')) then result := 'id2' else if (StrMatch(from, 'First3 Last3 ')) then result := 'id3' else if (StrMatch(from, 'First4 Last4 ')) then result := 'id4' else if (StrMatch(from, 'First5 Last5 ')) then result := 'id5' else if (StrMatch(from, 'First6 Last6 ')) 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. |
Thread Tools | |
Display Modes | Rate This Thread |
|
|