deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Mail::Box to view the mail in my mbox type mailbox, Parse it, then remove the read mail. Cant figure out how to remove it and could use some help. The script warns me that: WARNING: Changes not written to read-only folder /var/spool/mail/jlahowet. and I'm running as root. Is there another way?
#!/usr/bin/perl -w use strict; use Mail::Box::Manager; my $mailspool = "/var/spool/mail/jlahowet"; my $received = "/home/jlahowet/THOR/HAS/messages"; my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open(folder => $mailspool); my $type = $folder->type; print "$type\n"; my $name = $folder->name; print "$name\n"; my $emails = $folder->messages; print "$emails\n"; foreach my $message ($folder->messages) { print $message->get('Subject') || '<no subject>', "\n"; $message->delete; } $folder->close; exit;
UPDATE: Replacing the open command with my $folder = $mgr->open(folder => $mailspool, access => 'rw'); give write access the the folder and then you can delete it... but I can only do it as root. I "ls" the mail folder and got: -rw-------  1 jlahowet mail    3523 May 27 00:48 jlahowet. If I read this right, I own the file so I'm not sure why I have to be root to delete it.

Replies are listed 'Best First'.
Re: Mail::Box-deleting messages
by FloydATC (Deacon) on May 27, 2009 at 05:46 UTC
    From the Mail::Box documentation, diagnostics section:

    Warning: Changes not written to read-only folder $self.

    You have opened the folder read-only --which is the default set by new(access)--, made modifications, and now want to close it. Set close(force) if you want to overrule the access mode, or close the folder with close(write) set to NEVER.

    -- Time flies when you don't know what you're doing
Re: Mail::Box-deleting messages
by jethro (Monsignor) on May 27, 2009 at 08:38 UTC

    Answering the update: Try to change the file with an editor (as user jlahowet). If that works, it is still something with your script

    If you can't change the file, check the directories /var and /var/spool, they should have rx flags set for world (i.e. drwxr-xr-x ). And check mail, it should have drwxrwxrwt. That is the usual setting and without read/execute rights you can't traverse down these directories (read access is for actually reading a directory, execute right is the right to access a file in the directory if you already know its name