19

I am not trying to remove all the mails.

I googled for mark all mail as read, actually got posts saying how to delete them instead.

I found out using echo p | mail will output first of unread then mark it read, but if I do this, I have to loop through them.

I figured for all read mails, they will be appended to a file named mbox

What I am trying to do is...I want to create a bash file which is then used for crontab that let's say, at the end of each month, change the name of mbox into month-year in this way I can keep track and organize the mails BUT in order to have the mails appended into mbox is reading the mails one by one first.

Am I thinking this in a wrong direction? Or can someone give me some advices?

Thanks in advance for any help

EDIT: I am just using sudo apt install mailutils for my ubuntu server

Dora
  • 495
  • @dessert edited, that's the only thing I installed – Dora Jan 10 '18 at 22:18
  • You have to find or modify a script , example - http://www.aoakley.com/articles/2009-01-11-markallread.php . Please read the comments in the script and adjust accordingly. – Panther Jan 11 '18 at 01:27

3 Answers3

23

I was able to do it as follows:

  1. Type mail, it tell me how many unread messages I have. Let's say, 31.
  2. Type t 1-31, it displays all messages from 1 to 31 in a big concatenated sheet (turned out that t * achieves the same result, thanks to Jaime Hablutzel)
  3. Type q to quit view mode, type q again to quit mail

That's it! mail says all 31 messages saved in your mbox file, and next time you enter it, it will say "no mail for you".

  • 2
    This works perfectly on the macOS mail utility as well – Jay Dorsey Oct 08 '20 at 17:47
  • 3
    Isn't t * more straightforward?. – Jaime Hablutzel Mar 24 '21 at 18:16
  • 3
    In my case I wanted to delete all the mail messages. For this, all you need to do is: 1) type mail; 2) d *; 3) q – juanmirocks Sep 28 '21 at 12:14
  • I use Ubuntu 20.04. When I press q, it shows the next message. When I press Ctrl+C and then q, it marks as read only few messages. What am I doing wrong? – Finesse Jul 03 '22 at 02:43
  • I've solved it by making a text consisting only of many q letters and pasting it into the message display of mail – Finesse Jul 03 '22 at 03:22
  • if you still want to see your mail ever again, then you should follow that up with hold * and then q if you want to exit without shoving the mail off into the (home folder) void, then x and it will not persist any changes like which emails you've viewed – Dave Ankin Oct 16 '22 at 02:44
2

A minor improvement on Vlad's answer. If you are not interested in the content and just want to mark the mails read, the follow command is more efficient: top :u. The command "top" shows only the first few lines of the message and :u gives just unread messages.

Zanna
  • 72,471
Sam Wong
  • 21
  • 2
0

From the man page for mail:

seen

Takes a message list and marks all messages as having been read.

Therefore in mail;

? seen *

will mark all messages read without removing them.

Although it appears ubuntu mail doesn't have this command.