Browse Source

Add a script to distribute bdsmail to user maildirs

Bob Mottram 7 years ago
parent
commit
78bcc77896
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      src/freedombone-app-bdsmail

+ 23
- 0
src/freedombone-app-bdsmail View File

245
     if [ -d $BDSMAIL_DIR ]; then
245
     if [ -d $BDSMAIL_DIR ]; then
246
         rm -rf $BDSMAIL_DIR
246
         rm -rf $BDSMAIL_DIR
247
     fi
247
     fi
248
+    rm /usr/bin/bdsmail_domain
249
+    sed -i '/bdsmail_distribute/d' /etc/crontab
250
+    rm /usr/bin/bdsmail_distribute
248
 }
251
 }
249
 
252
 
250
 function install_bdsmail {
253
 function install_bdsmail {
342
     systemctl enable bdsmail
345
     systemctl enable bdsmail
343
     systemctl start bdsmail
346
     systemctl start bdsmail
344
 
347
 
348
+    echo '#!/bin/bash' > /usr/bin/bdsmail_distribute
349
+    echo 'BDSMAIL_DIR=/etc/bdsmail' >> /usr/bin/bdsmail_distribute
350
+    echo "MAIL_DIR=\$BDSMAIL_DIR/$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')" >> /usr/bin/bdsmail_distribute
351
+    echo 'if [ ! -d $MAIL_DIR/postmaster/new ]; then' >> /usr/bin/bdsmail_distribute
352
+    echo '    exit 0' >> /usr/bin/bdsmail_distribute
353
+    echo 'fi' >> /usr/bin/bdsmail_distribute
354
+    echo 'for filename in $MAIL_DIR/postmaster/new/*; do' >> /usr/bin/bdsmail_distribute
355
+    echo '    to_line=$(cat $filename | grep "To: " | head -n 1)' >> /usr/bin/bdsmail_distribute
356
+    echo "    to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')" >> /usr/bin/bdsmail_distribute
357
+    echo '    if [ -d /home/$to_username/Maildir/i2p/new ]; then' >> /usr/bin/bdsmail_distribute
358
+    echo '        chown $to_username:$to_username $filename' >> /usr/bin/bdsmail_distribute
359
+    echo '        mv $filename /home/$to_username/Maildir/i2p/new' >> /usr/bin/bdsmail_distribute
360
+    echo '    fi' >> /usr/bin/bdsmail_distribute
361
+    echo 'done' >> /usr/bin/bdsmail_distribute
362
+    chmod +x /usr/bin/bdsmail_distribute
363
+
364
+    if ! grep -q 'bdsmail_distribute' /etc/crontab; then
365
+        echo '*/1            * *   *   *   root /usr/bin/bdsmail_distribute 2> /dev/null' >> /etc/crontab
366
+    fi
367
+
345
     echo '#!/bin/bash' > /usr/bin/bdsmail_domain
368
     echo '#!/bin/bash' > /usr/bin/bdsmail_domain
346
     echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
369
     echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
347
     echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain
370
     echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain