0

在这个程序中,我将我的邮件内容分类到程序中,它应该只显示提到的字段(发件人:收件人:日期:主题:)和收件箱中每封电子邮件的邮件正文。我还是 BASH 的新手,所以如果你有答案,请解释一下。

 #! /bin/bash
    IFS=" "
    read first rest
    while [ $? -eq 0 -a "$first" == "From" ] ; do
         echo $first" "$rest
         :
         read first rest
         ###################################
         #
         while [ ! -z $first ] ; do
              #
              case "$first" in
                  "Date:" )
                  echo $first$rest
                  :
                  ;;
                  "From:" )
                  echo $first$rest
                  :
                  ;;
                  "To:" )
                  echo $first$rest
                  :
                  ;;
                  "Subject:" )
                  echo $first$rest
                  :
                  ;;
                  * )
 :
              ;;
          esac
          read first rest
     done
     ###################################
     #
     ##
     ##
     :
     read first rest
     ###################################
     #
     while [ ! -z $first ] ; do
          :
          echo $first" "$rest
          read first rest
     done
     read first rest
done
:
exit
4

1 回答 1

0
in_headers=true
while IFS= read -r line; do
    if $in_headers; then
        if [[ $line == "" ]]; then
            in_headers=false
        else
            case $line in 
                From:* | To:* | Date:* | Subject:*) : ;;
                *) continue ;;
            esac
        fi
    fi
    echo "$line"
done
于 2013-10-20T21:23:03.210 回答