Przeglądaj źródła

Option to remove a user from a mailing list

Bob Mottram 9 lat temu
rodzic
commit
cc07972c78
1 zmienionych plików z 98 dodań i 9 usunięć
  1. 98
    9
      src/freedombone-controlpanel

+ 98
- 9
src/freedombone-controlpanel Wyświetl plik

@@ -556,6 +556,93 @@ function change_ssh_public_key {
556 556
     esac
557 557
 }
558 558
 
559
+function remove_user_from_mailing_list {
560
+    select_user
561
+    if [ ! $SELECTED_USERNAME ]; then
562
+        return
563
+    fi
564
+    USER_MAILING_LISTS=$(cat "/home/$SELECTED_USERNAME/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
565
+
566
+    i=0
567
+    W=()
568
+    list_name=()
569
+    while read -r listname; do
570
+        i=$((i+1))
571
+        W+=($i "$listname")
572
+        list_name+=("$listname")
573
+        echo $listname
574
+    done <<< "$USER_MAILING_LISTS"
575
+
576
+    i=$((i+1))
577
+    W+=($i $"Exit back to user mainenance")
578
+
579
+    list_selected=$(dialog --default-item "$i" --backtitle $"Freedombone Control Panel" --title $"Remove a mailing list for $SELECTED_USERNAME" --menu $"Select one of the following:" 24 50 17 "${W[@]}" 3>&2 2>&1 1>&3)
580
+
581
+    if [ $? -eq 0 ]; then # Exit with OK
582
+        if [ ${list_selected} -ne ${i} ]; then
583
+            remove_list_name="${list_name[$((list_selected-1))]}"
584
+
585
+            # find the line number where the list is defined
586
+            line_number=0
587
+            i=0
588
+            while read -r line
589
+            do
590
+                if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
591
+                    line_number=${i}
592
+                fi
593
+                i=$((i+1))
594
+            done < "/home/$SELECTED_USERNAME/.procmailrc"
595
+
596
+            if [ ${line_number} -eq 0 ]; then
597
+                # no match was found
598
+                return
599
+            fi
600
+
601
+            # recreate the file
602
+            if [ -f /home/${SELECTED_USERNAME}/.procmailrc_new ]; then
603
+                rm /home/${SELECTED_USERNAME}/.procmailrc_new
604
+            fi
605
+            i=0
606
+            clip=0
607
+            while read -r line
608
+            do
609
+                i=$((i+1))
610
+                if [ ${i} -gt $((line_number-1)) ]; then
611
+                    if [ ${clip} -eq 0 ]; then
612
+                        clip=1
613
+                    fi
614
+                    if [ ${clip} -eq 1 ]; then
615
+                        if [ ${i} -lt $((line_number+2)) ]; then
616
+                            continue
617
+                        else
618
+                            if [ ${#line} -lt 1 ]; then
619
+                                clip=2
620
+                                continue
621
+                            fi
622
+                            if [[ "$line" == ":"* || "$line" == "#"* ]]; then
623
+                                clip=2
624
+                            else
625
+                                continue
626
+                            fi
627
+                        fi
628
+                    fi
629
+                fi
630
+
631
+                echo "$line" >> /home/${SELECTED_USERNAME}/.procmailrc_new
632
+
633
+                if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
634
+                    line_number=${i}
635
+                fi
636
+            done < "/home/$SELECTED_USERNAME/.procmailrc"
637
+            cp /home/${SELECTED_USERNAME}/.procmailrc_new /home/${SELECTED_USERNAME}/.procmailrc
638
+            rm /home/${SELECTED_USERNAME}/.procmailrc_new
639
+            chown ${SELECTED_USERNAME}:${SELECTED_USERNAME} /home/${SELECTED_USERNAME}/.procmailrc
640
+            dialog --title $"Remove user from mailing list" \
641
+                   --msgbox $"${SELECTED_USERNAME} has been removed from ${remove_list_name}" 6 50
642
+        fi
643
+    fi
644
+}
645
+
559 646
 function add_to_mailing_list {
560 647
     select_user
561 648
     if [ ! $SELECTED_USERNAME ]; then
@@ -1380,12 +1467,13 @@ function menu_email {
1380 1467
         trap "rm -f $data" 0 1 2 5 15
1381 1468
         dialog --backtitle $"Freedombone Control Panel" \
1382 1469
                --title $"Email Filtering Rules" \
1383
-               --radiolist $"Choose an operation:" 12 70 5 \
1470
+               --radiolist $"Choose an operation:" 13 70 6 \
1384 1471
                1 $"Add a user to a mailing list" off \
1385
-               2 $"Add an email rule" off \
1386
-               3 $"Block/Unblock an email address" off \
1387
-               4 $"Block/Unblock email with subject text" off \
1388
-               5 $"Back to main menu" on 2> $data
1472
+               2 $"Remove a user from a mailing list" off \
1473
+               3 $"Add an email rule" off \
1474
+               4 $"Block/Unblock an email address" off \
1475
+               5 $"Block/Unblock email with subject text" off \
1476
+               6 $"Back to main menu" on 2> $data
1389 1477
         sel=$?
1390 1478
         case $sel in
1391 1479
             1) break;;
@@ -1393,10 +1481,11 @@ function menu_email {
1393 1481
         esac
1394 1482
         case $(cat $data) in
1395 1483
             1) add_to_mailing_list;;
1396
-            2) email_rule;;
1397
-            3) block_unblock_email;;
1398
-            4) block_unblock_subject;;
1399
-            5) break;;
1484
+            2) remove_user_from_mailing_list;;
1485
+            3) email_rule;;
1486
+            4) block_unblock_email;;
1487
+            5) block_unblock_subject;;
1488
+            6) break;;
1400 1489
         esac
1401 1490
     done
1402 1491
 }