# +---------------------------------------------------+
# Configure Non Spam Behaviour
# +---------------------------------------------------+
function func_ask-nonspam() {
  func_echo-header

  echo -e ""
  echo -e "$green[eFa]$clean Non Spam Delivery and Retention Settings:"
  echo -e ""
  echo -e "$green[eFa]$clean By default, non spam is stored in the quarantine."
  echo -e "$green[eFa]$clean This allows a copy of each email to be retained"
  echo -e "$green[eFa]$clean for the retention period."
  echo -e ""
  echo -e "$green[eFa]$clean You can also choose to deliver non spam without"
  echo -e "$green[eFa]$clean storing it."
  echo -e ""
  echo -e -n "$green[eFa]$clean Do you want to $green DISABLE $clean storing non spam ? [y/N/c]: "

  read TMPSTORENSPAM
  STORENSPAM=""
  spamcheck=1
  while [ $spamcheck != "0" ]
    do 
      if [[ "$TMPSTORENSPAM" == "Y" || "$TMPSTORENSPAM" == "y" ]]; then
        # Set non spam delivery behavior
        STORENSPAM="deliver header \"X-Spam-Status:No\""
        echo -e "$green[eFa]$clean Non spam storage $green DISABLED $clean"
        spamcheck=0
        echo -e ""
        echo -e "Note: When non spam storage is disabled the inline signature"
        echo -e "\"Report this message as spam\" will not be able to submit"
        echo -e "messages to the bayesian filter."
        echo -e ""
        echo -e "Modify your Inline Signature Rules and remove all domains"
        echo -e "to receive an inline signature without \"Report this message"
        echo -e "as spam\" appended."
        echo -e "" 
      elif [[ "$TMPSTORENSPAM" == "" || "$TMPSTORENSPAM" == "N" || "$TMPSTORENSPAM" == "n" ]]; then 
        STORENSPAM="store deliver header \"X-Spam-Status:No\""
        echo -e "$green[eFa]$clean Non spam storage $green ENABLED $clean"
        spamcheck=0
      elif [[ "$TMPSTORENSPAM" == "C" || "$TMPSTORENSPAM" == "c" ]]; then
        echo -e "$green[eFa]$clean No action taken."
        pause
        return
      else
          echo -e "       $red ERROR: please make an selection.$clean"
          echo -e -n "$green[eFa]$clean Do you want to $green DISABLE $clean storing non spam ? [y/N/c]: "
          read TMPSTORENSPAM
      fi
  done

  echo -e ""
  echo -e "$green[eFa]$clean Non Spam Inline Signature Settings:"
  echo -e ""
  echo -e "$green[eFa]$clean By default, no signature is appended."
  echo -e "$green[eFa]$clean If enabled, a signature is appended"
  echo -e "$green[eFa]$clean depending on your inline signature rules."
  echo -e ""
  echo -e "$green[eFa]$clean You can choose to disable the signature entirely."
  echo -e ""
  echo -e -n "$green[eFa]$clean Do you want to $green ENABLE $clean non spam signatures ? [y/N/c]: "

  read TMPNSPAMSIG
  NSPAMSIG=""
  spamcheck=1
  while [ $spamcheck != "0" ]
    do 
      if [[ "$TMPNSPAMSIG" == "Y" || "$TMPNSPAMSIG" == "y" ]]; then
        # Set non spam delivery behavior
        NSPAMSIG="custom(nonspam)"
        echo -e "$green[eFa]$clean Non spam signatures $green ENABLED $clean"
        spamcheck=0
        sed -i "/^Non Spam Actions =/ c\Non Spam Actions = $STORENSPAM $NSPAMSIG" /etc/MailScanner/MailScanner.conf
        # Disable this in favor of custom(nonspam) action to sign messages instead
        sed -i "/^Sign Clean Messages =/ c\Sign Clean Messages = No" /etc/MailScanner/MailScanner.conf
        sed -i "/^Inline HTML Signature =/ c\Inline HTML Signature = %rules-dir%/inline.sig.html.rules" /etc/MailScanner/MailScanner.conf
        sed -i "/^Inline Text Signature =/ c\Inline Text Signature = %rules-dir%/inline.sig.text.rules" /etc/MailScanner/MailScanner.conf
        touch /etc/MailScanner/rules/inline.sig.html.rules
        touch /etc/MailScanner/rules/inline.sig.text.rules
        systemctl restart mailscanner
        pause
      elif [[ "$TMPNSPAMSIG" == "" || "$TMPNSPAMSIG" == "N" || "$TMPNSPAMSIG" == "n" ]]; then 
        NSPAMSIG=""
        echo -e "$green[eFa]$clean Non spam signatures $green DISABLED $clean"
        spamcheck=0
        sed -i "/Non Spam Actions =/ c\Non Spam Actions = $STORENSPAM $NSPAMSIG" /etc/MailScanner/MailScanner.conf
        sed -i "/^Sign Clean Messages =/ c\Sign Clean Messages = No" /etc/MailScanner/MailScanner.conf
        systemctl restart mailscanner
        pause
      elif [[ "$TMPNSPAMSIG" == "C" || "$TMPNSPAMSIG" == "c" ]]; then
        echo -e "$green[eFa]$clean No action taken, exiting."
        spamcheck=0
        pause
      else
          echo -e "       $red ERROR: please make an selection.$clean"
          echo -e -n "$green[eFa]$clean Do you want to $green ENABLE $clean non spam signatures? [y/N/c]: "
          read TMPSPAMSIG
      fi
  done
}
# +---------------------------------------------------+