Delete Mail Based on Subject Pattern [mail-command]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















Is it possible to delete all mail in which the subject matches a regex pattern?



For example, to delete message 1, you do:



d 1


But to delete all mail with subject starting with, say, [SPAM], I can't do:



d -s "^[SPAM].*$"









share|improve this question

















  • 1





    Can you use mutt? That can match-and-then-delete by pattern.

    – thrig
    Jan 17 '17 at 18:24






  • 2





    Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

    – dirkt
    Jan 17 '17 at 18:24











  • @thrig @dirkt Thanks for the suggestion! I will check out mutt.

    – nehcsivart
    Jan 17 '17 at 18:28















1















Is it possible to delete all mail in which the subject matches a regex pattern?



For example, to delete message 1, you do:



d 1


But to delete all mail with subject starting with, say, [SPAM], I can't do:



d -s "^[SPAM].*$"









share|improve this question

















  • 1





    Can you use mutt? That can match-and-then-delete by pattern.

    – thrig
    Jan 17 '17 at 18:24






  • 2





    Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

    – dirkt
    Jan 17 '17 at 18:24











  • @thrig @dirkt Thanks for the suggestion! I will check out mutt.

    – nehcsivart
    Jan 17 '17 at 18:28













1












1








1








Is it possible to delete all mail in which the subject matches a regex pattern?



For example, to delete message 1, you do:



d 1


But to delete all mail with subject starting with, say, [SPAM], I can't do:



d -s "^[SPAM].*$"









share|improve this question














Is it possible to delete all mail in which the subject matches a regex pattern?



For example, to delete message 1, you do:



d 1


But to delete all mail with subject starting with, say, [SPAM], I can't do:



d -s "^[SPAM].*$"






mail-command






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 17 '17 at 18:18









nehcsivartnehcsivart

363311




363311







  • 1





    Can you use mutt? That can match-and-then-delete by pattern.

    – thrig
    Jan 17 '17 at 18:24






  • 2





    Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

    – dirkt
    Jan 17 '17 at 18:24











  • @thrig @dirkt Thanks for the suggestion! I will check out mutt.

    – nehcsivart
    Jan 17 '17 at 18:28












  • 1





    Can you use mutt? That can match-and-then-delete by pattern.

    – thrig
    Jan 17 '17 at 18:24






  • 2





    Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

    – dirkt
    Jan 17 '17 at 18:24











  • @thrig @dirkt Thanks for the suggestion! I will check out mutt.

    – nehcsivart
    Jan 17 '17 at 18:28







1




1





Can you use mutt? That can match-and-then-delete by pattern.

– thrig
Jan 17 '17 at 18:24





Can you use mutt? That can match-and-then-delete by pattern.

– thrig
Jan 17 '17 at 18:24




2




2





Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

– dirkt
Jan 17 '17 at 18:24





Use another mail program, e.g. mutt: D to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them.

– dirkt
Jan 17 '17 at 18:24













@thrig @dirkt Thanks for the suggestion! I will check out mutt.

– nehcsivart
Jan 17 '17 at 18:28





@thrig @dirkt Thanks for the suggestion! I will check out mutt.

– nehcsivart
Jan 17 '17 at 18:28










3 Answers
3






active

oldest

votes


















1














I am answering this in case anyone comes by the same question.



It does not appear there is any way to do bulk deletion by pattern matching using mail.
An alternative is to use the mutt mail client, which does have such feature:



D [SPAM]


Thanks to @thrig and @dirkt for suggesting the alternative.






share|improve this answer























  • Please accept your answer.

    – Tripp Kinetics
    May 21 '18 at 18:30






  • 1





    @TrippKinetics Okay, I have accepted the answer.

    – nehcsivart
    May 21 '18 at 18:32


















0














According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use



(subject string)
All messages that contain string in the Subject: field.


In the mail command you would write:



& d (subject Happy Birthday)


This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")






share|improve this answer






























    0














    I was looking for the same without success, so I decided to try like this:



    echo 'f 1-$' | mail -N | grep 'SPAM' | awk 'print $1'


    Or print $0 to see the full header to show the mail number with the string 'SPAM'.



    So if you think is ok you can delete all of this.



    echo 'd #1 #2 #3 ...' | mail -N


    Or make a full script.






    share|improve this answer

























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f338115%2fdelete-mail-based-on-subject-pattern-mail-command%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I am answering this in case anyone comes by the same question.



      It does not appear there is any way to do bulk deletion by pattern matching using mail.
      An alternative is to use the mutt mail client, which does have such feature:



      D [SPAM]


      Thanks to @thrig and @dirkt for suggesting the alternative.






      share|improve this answer























      • Please accept your answer.

        – Tripp Kinetics
        May 21 '18 at 18:30






      • 1





        @TrippKinetics Okay, I have accepted the answer.

        – nehcsivart
        May 21 '18 at 18:32















      1














      I am answering this in case anyone comes by the same question.



      It does not appear there is any way to do bulk deletion by pattern matching using mail.
      An alternative is to use the mutt mail client, which does have such feature:



      D [SPAM]


      Thanks to @thrig and @dirkt for suggesting the alternative.






      share|improve this answer























      • Please accept your answer.

        – Tripp Kinetics
        May 21 '18 at 18:30






      • 1





        @TrippKinetics Okay, I have accepted the answer.

        – nehcsivart
        May 21 '18 at 18:32













      1












      1








      1







      I am answering this in case anyone comes by the same question.



      It does not appear there is any way to do bulk deletion by pattern matching using mail.
      An alternative is to use the mutt mail client, which does have such feature:



      D [SPAM]


      Thanks to @thrig and @dirkt for suggesting the alternative.






      share|improve this answer













      I am answering this in case anyone comes by the same question.



      It does not appear there is any way to do bulk deletion by pattern matching using mail.
      An alternative is to use the mutt mail client, which does have such feature:



      D [SPAM]


      Thanks to @thrig and @dirkt for suggesting the alternative.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 18 '17 at 22:56









      nehcsivartnehcsivart

      363311




      363311












      • Please accept your answer.

        – Tripp Kinetics
        May 21 '18 at 18:30






      • 1





        @TrippKinetics Okay, I have accepted the answer.

        – nehcsivart
        May 21 '18 at 18:32

















      • Please accept your answer.

        – Tripp Kinetics
        May 21 '18 at 18:30






      • 1





        @TrippKinetics Okay, I have accepted the answer.

        – nehcsivart
        May 21 '18 at 18:32
















      Please accept your answer.

      – Tripp Kinetics
      May 21 '18 at 18:30





      Please accept your answer.

      – Tripp Kinetics
      May 21 '18 at 18:30




      1




      1





      @TrippKinetics Okay, I have accepted the answer.

      – nehcsivart
      May 21 '18 at 18:32





      @TrippKinetics Okay, I have accepted the answer.

      – nehcsivart
      May 21 '18 at 18:32













      0














      According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use



      (subject string)
      All messages that contain string in the Subject: field.


      In the mail command you would write:



      & d (subject Happy Birthday)


      This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")






      share|improve this answer



























        0














        According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use



        (subject string)
        All messages that contain string in the Subject: field.


        In the mail command you would write:



        & d (subject Happy Birthday)


        This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")






        share|improve this answer

























          0












          0








          0







          According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use



          (subject string)
          All messages that contain string in the Subject: field.


          In the mail command you would write:



          & d (subject Happy Birthday)


          This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")






          share|improve this answer













          According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use



          (subject string)
          All messages that contain string in the Subject: field.


          In the mail command you would write:



          & d (subject Happy Birthday)


          This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 1 at 10:04









          user339460user339460

          1




          1





















              0














              I was looking for the same without success, so I decided to try like this:



              echo 'f 1-$' | mail -N | grep 'SPAM' | awk 'print $1'


              Or print $0 to see the full header to show the mail number with the string 'SPAM'.



              So if you think is ok you can delete all of this.



              echo 'd #1 #2 #3 ...' | mail -N


              Or make a full script.






              share|improve this answer





























                0














                I was looking for the same without success, so I decided to try like this:



                echo 'f 1-$' | mail -N | grep 'SPAM' | awk 'print $1'


                Or print $0 to see the full header to show the mail number with the string 'SPAM'.



                So if you think is ok you can delete all of this.



                echo 'd #1 #2 #3 ...' | mail -N


                Or make a full script.






                share|improve this answer



























                  0












                  0








                  0







                  I was looking for the same without success, so I decided to try like this:



                  echo 'f 1-$' | mail -N | grep 'SPAM' | awk 'print $1'


                  Or print $0 to see the full header to show the mail number with the string 'SPAM'.



                  So if you think is ok you can delete all of this.



                  echo 'd #1 #2 #3 ...' | mail -N


                  Or make a full script.






                  share|improve this answer















                  I was looking for the same without success, so I decided to try like this:



                  echo 'f 1-$' | mail -N | grep 'SPAM' | awk 'print $1'


                  Or print $0 to see the full header to show the mail number with the string 'SPAM'.



                  So if you think is ok you can delete all of this.



                  echo 'd #1 #2 #3 ...' | mail -N


                  Or make a full script.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 1 at 20:42









                  Christopher

                  10.8k33249




                  10.8k33249










                  answered Mar 1 at 20:05









                  CarlosCarlos

                  1




                  1



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f338115%2fdelete-mail-based-on-subject-pattern-mail-command%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown






                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)