Mercurial > hgrepos > hgweb.cgi > 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 wrap: on
line diff
--- a/s4-funcs.sh Fri Apr 17 18:15:40 2020 +0900 +++ b/s4-funcs.sh Fri Apr 17 18:17:26 2020 +0900 @@ -13,6 +13,7 @@ dbdir=${DBDIR:-db} tmpfiles="" db=${DB:-$dbdir/cgi.sq3} +workdb=$dbdir/tmpdata.sq3 listentlimit=${LISTENTLIMIT:-30} admin=${ADMIN:-hostmaster@example.org} noreply=${NOREPLY:-noreply@example.org} @@ -1145,6 +1146,68 @@ (_m4 -D_RCPT_="${SMAIL_TO:-$rcpt}" -D_SUBJ_="\`$subj'" -D_FROM_="$from" $msgdir/mail-header.m4 cat $3 | nkf -jd ) | sendmail -f $admin $rcpt } +smail_queue_flush() { + # $1=timelimit + timelimit=`sq $workdb "SELECT datetime('now', 'localtime', '-1 minutes');"` + err timelimit="$timelimit" rowid=$rowid + err r===="$(sq $workdb <<-EOF + SELECT rowid FROM smailq + GROUP BY rcpts, subj + HAVING min(time) < '$timelimit'; + EOF + )" + rowids=$(sq $workdb <<-EOF + SELECT rowid FROM smailq + GROUP BY rcpts, subj + HAVING min(time) < '$timelimit'; + EOF + ) + for rid in $rowids; do + sq $workdb \ + "SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid in ($rid)" \ + | if IFS='|' read hexr hexs; then + err "hexrcpt=[$hexr] hexsubj=[$hexs]" + rcpt=`echo "$hexr"|unhexize` + subj=`echo "$hexs"|unhexize` + + # err ROWID==$rowid "sql=<<SELECT hex(rcpts),hex(subj) FROM smailq WHERE rowid=$rowid;>>" + err "rcpt=[$rcpt] subj=[$subj]" + if sq $workdb <<-EOF | smail "$rcpt" "$subj" + .separator "\n" "------------------\n\n" + SELECT time, text FROM smailq + WHERE rcpts=(SELECT rcpts FROM smailq WHERE rowid=$rid) + AND subj=(SELECT subj FROM smailq WHERE rowid=$rid) + ORDER by time; + EOF + then + echo rowid=$rid + cat <<-EOF | sq $workdb + DELETE FROM smailq + WHERE rcpts=(SELECT rcpts FROM smailq WHERE rowid=$rid) + AND subj=(SELECT subj FROM smailq WHERE rowid=$rid); + EOF + fi + fi + done +} +smail_queue() { + # $1=Rcpts, $@=subj + now=`sq $workdb "SELECT datetime('now', 'localtime');"` + if [ $? -eq 0 ]; then + rcpts="X'"`echo "$1"|hexize`"'" + subj="X'"`echo "$2"|hexize`"'" + text="X'"`cat | hexize`"'" + err "rcpts=[$rcpts] s=[$subj] t=[$text]" + mintime=$(tee /tmp/sql <<-EOF | sq $workdb + CREATE TABLE IF NOT EXISTS smailq(rcpts, subj, text, time); + INSERT INTO smailq VALUES($rcpts, $subj, $text, '$now'); + SELECT min(time) FROM smailq WHERE rcpts=$rcpts AND subj=$subj; + EOF + ) + err flush_queue=$mintime + smail_queue_flush + fi +} setviastring() { table=$1 oifs="$IFS" @@ -3082,7 +3145,7 @@ end;" action="から脱退しました。" fi - smail "$(collectemail `getgroupadmins $1`)" "Member change of $1"<<-EOF + smail_queue "$(collectemail `getgroupadmins $1`)" "Member change of $1"<<-EOF $url?grp+$grid $user (`gecos $user`)さんが グループ $1