s4
changeset 614:962c954715b8
smail_queue() initially implemented
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 17 Apr 2020 18:17:26 +0900 |
parents | 51e0cc07a79a |
children | a2d595d5605b |
files | s4-funcs.sh |
diffstat | 1 files changed, 64 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/s4-funcs.sh Fri Apr 17 18:15:40 2020 +0900 1.2 +++ b/s4-funcs.sh Fri Apr 17 18:17:26 2020 +0900 1.3 @@ -13,6 +13,7 @@ 1.4 dbdir=${DBDIR:-db} 1.5 tmpfiles="" 1.6 db=${DB:-$dbdir/cgi.sq3} 1.7 +workdb=$dbdir/tmpdata.sq3 1.8 listentlimit=${LISTENTLIMIT:-30} 1.9 admin=${ADMIN:-hostmaster@example.org} 1.10 noreply=${NOREPLY:-noreply@example.org} 1.11 @@ -1145,6 +1146,68 @@ 1.12 (_m4 -D_RCPT_="${SMAIL_TO:-$rcpt}" -D_SUBJ_="\`$subj'" -D_FROM_="$from" $msgdir/mail-header.m4 1.13 cat $3 | nkf -jd ) | sendmail -f $admin $rcpt 1.14 } 1.15 +smail_queue_flush() { 1.16 + # $1=timelimit 1.17 + timelimit=`sq $workdb "SELECT datetime('now', 'localtime', '-1 minutes');"` 1.18 + err timelimit="$timelimit" rowid=$rowid 1.19 + err r===="$(sq $workdb <<-EOF 1.20 + SELECT rowid FROM smailq 1.21 + GROUP BY rcpts, subj 1.22 + HAVING min(time) < '$timelimit'; 1.23 + EOF 1.24 + )" 1.25 + rowids=$(sq $workdb <<-EOF 1.26 + SELECT rowid FROM smailq 1.27 + GROUP BY rcpts, subj 1.28 + HAVING min(time) < '$timelimit'; 1.29 + EOF 1.30 + ) 1.31 + for rid in $rowids; do 1.32 + sq $workdb \ 1.33 + "SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid in ($rid)" \ 1.34 + | if IFS='|' read hexr hexs; then 1.35 + err "hexrcpt=[$hexr] hexsubj=[$hexs]" 1.36 + rcpt=`echo "$hexr"|unhexize` 1.37 + subj=`echo "$hexs"|unhexize` 1.38 + 1.39 + # err ROWID==$rowid "sql=<<SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid=$rowid;>>" 1.40 + err "rcpt=[$rcpt] subj=[$subj]" 1.41 + if sq $workdb <<-EOF | smail "$rcpt" "$subj" 1.42 + .separator "\n" "------------------\n\n" 1.43 + SELECT time, text FROM smailq 1.44 + WHERE rcpts=(SELECT rcpts FROM smailq WHERE rowid=$rid) 1.45 + AND subj=(SELECT subj FROM smailq WHERE rowid=$rid) 1.46 + ORDER by time; 1.47 + EOF 1.48 + then 1.49 + echo rowid=$rid 1.50 + cat <<-EOF | sq $workdb 1.51 + DELETE FROM smailq 1.52 + WHERE rcpts=(SELECT rcpts FROM smailq WHERE rowid=$rid) 1.53 + AND subj=(SELECT subj FROM smailq WHERE rowid=$rid); 1.54 + EOF 1.55 + fi 1.56 + fi 1.57 + done 1.58 +} 1.59 +smail_queue() { 1.60 + # $1=Rcpts, $@=subj 1.61 + now=`sq $workdb "SELECT datetime('now', 'localtime');"` 1.62 + if [ $? -eq 0 ]; then 1.63 + rcpts="X'"`echo "$1"|hexize`"'" 1.64 + subj="X'"`echo "$2"|hexize`"'" 1.65 + text="X'"`cat | hexize`"'" 1.66 + err "rcpts=[$rcpts] s=[$subj] t=[$text]" 1.67 + mintime=$(tee /tmp/sql <<-EOF | sq $workdb 1.68 + CREATE TABLE IF NOT EXISTS smailq(rcpts, subj, text, time); 1.69 + INSERT INTO smailq VALUES($rcpts, $subj, $text, '$now'); 1.70 + SELECT min(time) FROM smailq WHERE rcpts=$rcpts AND subj=$subj; 1.71 + EOF 1.72 + ) 1.73 + err flush_queue=$mintime 1.74 + smail_queue_flush 1.75 + fi 1.76 +} 1.77 setviastring() { 1.78 table=$1 1.79 oifs="$IFS" 1.80 @@ -3082,7 +3145,7 @@ 1.81 end;" 1.82 action="から脱退しました。" 1.83 fi 1.84 - smail "$(collectemail `getgroupadmins $1`)" "Member change of $1"<<-EOF 1.85 + smail_queue "$(collectemail `getgroupadmins $1`)" "Member change of $1"<<-EOF 1.86 $url?grp+$grid 1.87 $user (`gecos $user`)さんが 1.88 グループ $1