Small sh "framework" to test some server responses
sh
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

mail.sh 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #Copyright (C) 2016,2023 Weber Yann
  2. #
  3. #This program is free software; you can redistribute it and/or modify
  4. #it under the terms of the GNU General Public License as published by
  5. #the Free Software Foundation; either version 3 of the License, or
  6. #any later version.
  7. #
  8. #This program is distributed in the hope that it will be useful,
  9. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. #GNU General Public License for more details.
  12. #
  13. #You should have received a copy of the GNU General Public License
  14. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. check_smtp() {
  16. hostname=$1
  17. port=$2
  18. ipv_arg=$3
  19. if [ -z "$port" ]
  20. then
  21. port=587
  22. fi
  23. case "$ipv_arg" in
  24. ipv4)ipv=-4;;
  25. ipv6)ipv=-6;;
  26. *)ipv="";;
  27. esac
  28. code=$(nc $ipv -q0 "$hostname" "$port" < /dev/null | cut -d " " -f1)
  29. if [ "$code" = "220" ]
  30. then
  31. success "SMTP@$hostname $ipv_arg server replied 220 status"
  32. else
  33. fail "Unexpected reply from smtp@$hostname $ipv_arg '$code'"
  34. fi
  35. }
  36. check_smtp_id() {
  37. hostname=$1
  38. idstr=$2
  39. port=$3
  40. ipv=$4
  41. if [ -z "$port" ]
  42. then
  43. port=587
  44. fi
  45. case "$ipv_arg" in
  46. ipv4)ipv=-4;;
  47. ipv6)ipv=-6;;
  48. *)ipv="";;
  49. esac
  50. rep=$(nc $ipv -q0 "$hostname" "$port" < /dev/null)
  51. if echo "$rep" | grep -e "^220 $idstr" > /dev/null
  52. then
  53. success "SMTP@$hostname $ipv_arg server replie '$idstr'"
  54. else
  55. fail "Unexpected reply from smtp@$hostname $ipv_arg '$rep'"
  56. fi
  57. }
  58. check_imaps() {
  59. hostname=$1
  60. port=$2
  61. ipv=$3
  62. if [ -z "$port" ]
  63. then
  64. port=993
  65. fi
  66. case "$ipv_arg" in
  67. ipv4)ipv=-4;;
  68. ipv6)ipv=-6;;
  69. *)ipv="";;
  70. esac
  71. rep=$(echo "01 LOGOUT" | openssl s_client $ipv -quiet -verify_quiet -connect "${hostname}:$port" -servername "$hostname")
  72. if echo "$rep" | grep "^01 OK" > /dev/null
  73. then
  74. success "IMAPS@$hostname $ipv_arg '$(echo "$rep" | grep "^01 OK")'"
  75. else
  76. fail "Unexpected reply from imaps@$hostname $ipv_arg '$rep'"
  77. fi
  78. }