#!/bin/bash ## sendtoElist -- Eugene Reimer 2006nov21 ## PREREQ: generateElistFromHISTORY+MBRS ListSubtract-e -- from http://ereimer.net/programs/ertools.zip ## PREREQ: jed -- from http://www.jedsoft.org/jed/ -- OR: any text-editor; SEE the line TEXTEDIT=... below ## ## Usage: ## sendtoElist email-file -- first prepare email-file, possibly by composing in Thunderbird then saving to a file (SEE NOTES below); ## sendtoElist email-file*MBRS* -- first prepare email-file... this variant sends to-members-only (new 2009-04) ## sendtoElist email-file-TBR -- first prepare email-file-TBR -- for sending to the current ToBeRemoved recipient-list (new 2007-Oct); ## sendtoElist email-file recipient-file -- first prepare email-file and recipient-file(Mailing-List) (new 2007-Nov01); ## ## For the first 3 forms: ## calls generateElistFromHISTORY+MBRS if needed => running fixPeggyMBRS beforehand is now optional (but would serve to verify that MBRS-format unchanged); ## note: resending a previously-sent email, means: send only to the Elist-Additions (those not-yet-sent-to, based on the LOG); ## ## The 3rd form, when $1 ends in "TBR", uses the alternate recipient-list Elist-AboutToBeRemoved-YYYY -- as produced by generateElistFromHISTORY+MBRS; ## and appends to LOG-file without "TBR" in the name -- so the log-file can be shared with a normal emailing to entire elist. ## ## The 4th form (2 operands), also keeps a LOG, and a resuming resend is now supported (==new 2008-04-30); ## (used on 2007nov02 to send to ELIST-Regina and ELIST-OrchidMall) ## (used on 2007nov07 to send to ELIST-OrchidMall*-UNDERSCORE-FIXUPS and ELIST-OrchidWire*-lessOrchidMall) ## (used on 2007dec22 to send to MERRY-MerryChristmas-reipient-list) ## ## User gets to view & revise: outgoing email, list of recipients; ## Sends one email to $ME (as a sample), then waits for keyboard input, giving user ($ME) a chance to Ctrl+C Abort. TEXTEDIT=jed ##==CUSTOMIZE AS NEEDED== [ $# -eq 1 ] && { FROM="NOCI-elist"; ME=ereimer@shaw.ca; } ##Noci-elist mailings to show "From: NOCI-elist " [ $# -eq 2 ] && { FROM="Eugene Reimer"; ME=ereimer@shaw.ca; } ##RECIP-LIST mailings to show "From: Eugene Reimer " (new 2007dec22) [[ $1 == *MBRS* ]] && { FROM="NOCI-mbrs-elist"; ME=ereimer@shaw.ca; } ##want MBRSONLY-Elist to show "From: NOCI-mbrs-elist " (new 2009-04) [[ $2 == *ELIST* ]] && { FROM="NativeOrchid.ORG"; ME=reimer2@shaw.ca; } ##want "bulk" mailings to show "From: NativeOrchid.ORG " [ $# -ne 1 ] && [ $# -ne 2 ] && { echo "usage: sendtoElist email-file [recip-list]"; exit; } ##ensure one or two positional-params: email-file [recip-list] { echo "From: $FROM <$ME>"; egrep -v '^(From:|To:|Date:|Message-ID:|User-Agent:|X-Mozilla-S|X-Accept-L)' $1; ##make fixed-up email-file (for manually or Thunderbird created) } >tmpEmail ##echo -n "View Outgoing-email ??"; read; $TEXTEDIT tmpEmail ##View+Revise the Outgoing-Email -- YANKED if [ $# -eq 1 ];then ##(condition is new 2007nov01) HTS=10#$(date -rElist-HISTORY +%y%m%d%H%M) ##get HTS = timestamp of Elist-HISTORY for f in MBRS*xls; do MBRXLS=$f; done; MTS=10#$(date -r$MBRXLS +%y%m%d%H%M) ##get MTS = timestamp of newest MBRS-*[-BIG].xls for f in Elist-20??????; do ELIST=$f; done; ETS=10#$(date -r$ELIST +%y%m%d%H%M) ##get ETS = timestamp of newest Elist-YYYYMMDD echo "HTS:$HTS MTS:$MTS ETS:$ETS:"; ##read ##DEBUG #if ((HTS>ETS)) || ((MTS>ETS)); then ##if Elist-HISTORY or MBRS newerthan Elist if [[ $1 == *MBRS* ]];then export MBRSONLY=1; fi ##==2009-04-21: global var for generateElistFromHISTORY+MBRS echo "running generateElistFromHISTORY+MBRS"; generateElistFromHISTORY+MBRS ##then generate a new Elist for f in Elist-20??????; do ELIST=$f; done ##and revise ELIST = name of newest Elist-YYYYMMDD #fi fi if [ $# -eq 2 ] && [[ $2 == *ELIST* ]];then ##Sending to an ELIST-Recip-List (new 2007nov01) for f in Elist-20??????; do Elist=$f; done ##find newest Elist, in order to ListSubtract those ListSubtract-e $2 $Elist >tmpPre ##create Prelim-Recip-List using ListSubtract if [ -e $1-LOG ];then R="($2 less $Elist less $1-LOG)"; else R="($2 less $Elist)"; fi ##create msg (2008-04-30) if [ -e $1-LOG ];then ListSubtract-e tmpPre $1-LOG; else cat tmpPre; fi >tmpRecip ##create Recip-List by ListSubtracting LOG if is (2008-04-30) echo "will be sending $1 to $R" elif [ $# -eq 2 ];then ##Sending to other cmdline-specified Recip-List (new 2007dec22) if [ -e $1-LOG ];then R="($2 less $1-LOG)"; else R="$2"; fi ##create msg if [ -e $1-LOG ];then ListSubtract-e $2 $1-LOG; else cat $2; fi >tmpRecip ##create Recip-List by ListSubtracting LOG, if it exists echo "will be sending $1 to $R" elif [[ $1 == *TBR ]];then ##Sending a TBR email to the AboutToBeRemoved-list (2007oct) TBRLIST=Elist-AboutToBeRemoved-$(date +%Y) ##get name of ToBeRemoved list for current year [ -e $TBRLIST ] || { echo "need $TBRLIST"; exit; } ##and ensure that list exists cat $TBRLIST >tmpRecip ##create a TBR Recip-List echo "will be sending $1 to those on $TBRLIST" elif [ -e $1-LOG ]; then ##LOG exists => re-sending-to-those-Not-Yet-Sent-To ListSubtract-e $ELIST $1-LOG >tmpRecip ##create Not-Yet-Sent-To Recip-list echo "will be re-sending $1 only to those on $ELIST yet to receive it" else ##Otherwise, a first-time sending-to-Elist grep -v "^$ME" $ELIST >tmpRecip ##create $ME-less Elist as Recip-list echo "will be sending $1 to all those on $ELIST" fi echo -n "View Recipient-list ??"; read; $TEXTEDIT tmpRecip ##--Chance to View+Revise the Recipient-List-- { echo "To: SENDTO-SAMPLE <$ME>"; cat tmpEmail; } |sendmail -it -f$ME ##send sample email to myself; -f for Return-Path echo -n "HAVE SENT a sample to $ME -- CONTINUE ??" ##prompt read ##--CHANCE to Ctrl+C ABORT if sample no good-- { echo "=====BEGIN EMAIL====="; head -n75 tmpEmail; echo "=====END EMAIL====="; } >>${1%-TBR}-LOG ##log Outgoing-Email if OK (07oct: %-TBR; 08apr: max 75 lines) echo "$(date +%Y%m%d-%H%M%S): sent to $ME" >>${1%-TBR}-LOG ##log the sent-time & id (2007oct: %-TBR) while read;do ##--process Recip-List (tmpRecip) line-by-line-- { echo "To: $REPLY"; cat tmpEmail; } |sendmail -it -f$ME ##--send to one id in Recip-List; -f for Return-Path-- echo "sent to $REPLY" ##YANK if this gets tiresome; can view the LOG echo "$(date +%Y%m%d-%H%M%S): sent to $REPLY" >>${1%-TBR}-LOG ##log the sent-time & id (2007oct: remove -TBR for log-name) done another type of forgery? With -t can still supply additional "BCC" recipients on cmdline; Note: recipients supplied on cmdline receive exactly the "BCC" treatment => not what I want for Elist-mailings! Configuring sendmail: 06nov13: configured it for outgoing mail via shawmail.wp.shawcable.net (consider changing to gmail - see info on google's website) change one line in /etc/mail/sendmail.mc; then: make -C /etc/mail then: kill ... ; /usr/sbin/sendmail -bd -os (to restart the sendmail daemon) configuring info at: http://www.linuxfocus.org/English/May2000/article130.shtml Bounce-emails: want them to go to ME (to ereimer@shaw.ca, not to root/ereimer@S010600e029965b45.wp.shawcable.net) (1) sent test-cases to: xyznotfound@mts.net vbdrb@aol.com (bounced yesterday 06nov13) <-- BUT HEARD NOTHING (2) adding a Return-path to input fails: sendmail overrides it with one for root/ereimer@...shawcable.net:-( AHA, just need -f option on cmdline, and that WORKS -- have tested, and received the bounce-email. Here's a SIMPLE EXAMPLE of an email that works with this sendmail-based approach (without the "## " beginning each line): -- can omit both "From:" and "To:" lines -- this script generates those, after removing any that were present in the input; -- can also use: Content-Type: text/plain; charset=us-ascii; format=flowed -- see <> script for other tested variations; for a PlainText+HTML example see: Elist-sendto-20061122-DecemberNewsletter.eml To: adames@mts.net From: NOCI-elist Subject: Test Message MIME-Version: 1.0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit ...Another test... Simple HTML-reformatting: sed-cmds for /easy-HTML/, replace double-space with " "+space, empty-line with "

": |sed 's| |\  |g; s|^$|

|' CONSIDER: also convert a "word" beginning with "http://" to a clickable-link?? (but not based on "www" and never for strings containing "@") (Avoid including punctuation chars that follow the URL; or, base on punctuation chars that can occur within an URL?) Making it easy to prepare elist-emails in text-editor with WYSIWYG behaviour for simple things... May end up enhancing this until I happily use it for all my email:-) Text/Plain + Format=Flowed (see RFC2646): Rule-1: each line (except last in paragraph) needs an ending Space! - more formally: Space+NL is a "soft" linebreak (use "hard" linebreak to end paragraph, or after each point...) - last line of paragraph can also have ending space, but then the following empty-line must not Rule-2: add a leading space to line beginning with "From" or a ">" which is not a quote-indicator! ergo, any line starting with ">" is Quoted; any line ending with space is Flowable. Recommended: flowed parts consist of lines at most 79 chars long, but avoid breaking a word longer than that; in no case may a line be longer than 998 chars (SMTP restriction). - a single long line (<=998) per paragraph would likely work for all mail-readers, and nicely for most? Message Format decision needed: Format-Flowed plain-text sounds good at first glance, but generating manually would be too glitch-prone? also, the Microsoft emailers IGNORE Format-Flowed => it's not suitable for using as the only format--!!-- HTML-only is ok for generating manually - the downside: some people still use plain-text readers? A) write a script that systematically converts an HTML-only email into a BOTH-plaintext+HTML email--??-- B) even simpler: do such conversion but using a fixed piece of text for the text/plain portion--??-- (it always says: The http://www.nativeorchid.org website has been updated.) C) use plaintext, but with a script to convert it into legal Format-Flowed format--??-- (identifying point-form is not easy) D) can use Thunderbird to compose, save to file, revise it in text-editor if needed, then send it to e-list... NO MATTER WHICH METHOD, the sending script first sends testcase to me, giving me a chance to see it in Thunderbird. 06nov22: COMPOSING IN THUNDERBIRD EXPERIMENTS: -- saving from compose-window is no good - the result is headerless -- saving a Draft from mail-viewing window is no good - is HTML-only (method would be fine if sending HTML-only were deemed adequate) -- Must send it, then save OUTGOING copy, in order to get a BOTH (plain-text+HTML) formatted email, with the desired header order -- (saving the RECEIVED copy was no good, since header-lines get re-ordered; HAVE SINCE REVISED script to handle any order) After learning about: (1) the myriad ways to go wrong, (2) the painful number of steps required to get a Both-PlainText+HTML email, (3) the ugliness of generated-HTML, especially for links (span & class), CONCLUSIONS: -- Thunderbird is NOT simple, is NOT the right answer!! ==> go back to plan-A, for future use, where I'll prepare such an email with text-editor; ==> revise this script to receive only Subject-line + HTML-body; it generates the rest of the header-lines, and the plain-text part. =========== CHANGE-LOG: =========== ==Consider: making most of this into a simpler script: sendto EMAIL-file RECIP-LIST-file [LOG-file] ==on a resend, NO NEED to copy to LOG if email unchanged, nor to send sample in that case (when email olderthan log) 2009-04-21: new MBRSONLY variant; see MBRSONLY lines in generateElistFromHISTORY+MBRS; TEMP?? made generateElistFromHISTORY+MBRS unconditional -- so switching between MBRSONLY and Full-Elist works; seems harmless; ===================================== 2009-08-05: HOW NOT TO IGNORE A TBR-LIST: (was in /books/Elist-HISTORY) ===================================== --Catenate it onto tmpRecip, then Rename it; --that way the current sendto-elist-emailing goes to them too, AND the next MBRS-conversion will make a new TBR-list; --example renaming: Elist-AboutToBeRemoved-2009 --> Elist-About-Ignored-TBR-list-from20090805; ==NOT THAT SIMPLE==!!== because generating TBR-list is done from the Elist-diff-file... ==MAY NEED A RETHINK; made a mess when deciding my MBRS-db not sufficiently current in 2009-08 -- better just to use such TBR-list with explanation about dates... ==FIXING 2009-10: ran fixPeggyMBRS MBRS200908.xls; redo sendto... it will send to hans007? make new TBR-list? ==NOPE and NOPE(empty) --AHA, due to "re-using previously extracted MBR-email-ids"; manually made TBR-list; starting with old one, removing any having "+" in subsequent Elist-diff-file; revised the TBR-email to contain "see frontpage..." as well as "being removed", then sent it; also sent original email to hans007;