]> gitweb.fluxo.info Git - firma.git/commitdiff
added function UnsubscribeUser
authorrhatto <rhatto>
Mon, 9 Oct 2006 12:45:06 +0000 (12:45 +0000)
committerrhatto <rhatto>
Mon, 9 Oct 2006 12:45:06 +0000 (12:45 +0000)
firma

diff --git a/firma b/firma
index 1f75e8a7b10b4bedc7f5c15cf11e765e7c33f787..d676bd6556712eeb26ebf44e889e3481eff94ac3 100755 (executable)
--- a/firma
+++ b/firma
@@ -934,7 +934,8 @@ function ListAdministration {
   quit                quit this prompt
   help                show this help
   use EMAIL-ADDRESS   use the given address for message delivery instead
-                        of the primary address on key
+                      of the primary address on key
+  unsub EMAIL-ADDRESS unsubscribe an email from the list
 "
           ;;
         quit)
@@ -1151,9 +1152,46 @@ function CheckValidEmail {
 
 
 function UnsubscribeUser {
-  # TODO: usubscribe if $1 is subscriber
-  #       always fix list folder permissions
-  true
+  #-------------------------------------------------------------
+  # unsubscribe a user and remove its pubkey from
+  #+the list keyring
+  #
+  # parameter(s): chosen email address
+  # depends on function(s): DeclareGpgVars
+  # returns: 0 on success,
+  #          1 if task can't be executed (public key not found, etc.)
+  #-------------------------------------------------------------
+
+  local key
+  local -i return_code=0
+  local keyid="$($GPG_LIST_KEYS --with-fingerprint $1 2> /dev/null | grep ^fpr | cut -d : -f 10)"
+  local uid_count="$($GPG_LIST_KEYS --fixed-list-mode $keyid 2> /dev/null | grep ^uid | wc -l)"
+  local chosen_uid_number="$($GPG_LIST_KEYS --fixed-list-mode $keyid 2> /dev/null | grep ^uid | grep -ni "$1" | cut -d : -f 1)"
+
+  if [ "$1" == "$LIST_ADDRESS" ]; then
+    # check if user is trying to unsubscribe the list key
+    return_code=1
+    echo >&2 "can't delete the list pubkey."
+  elif [[ -z "$($GPG_LIST_KEYS --fixed-list-mode "<$1>" 2> /dev/null | grep -v '^tru:')" ]]; then
+    # check if supplied address is associated with a public key
+    echo >&2 "use: \"$1\" is not associated with any public key on this keyring."
+    return_code=1
+  else
+    for key in $keyid; do
+      $GPG --batch --delete-key --yes $key
+      if [ "$?" == "0" ]; then
+        echo >&2 "deleted key id $key for $1"
+        # now just update the trust db
+        $GPG_LIST_KEYS &> /dev/null
+      else
+        echo >&2 "error deleting key id $key for $1"
+        return_code=1
+      fi
+    done
+  fi
+
+  chown -R $USER.$GROUP $LIST_PATH
+  return $return_code
 }