[EMAIL PROTECTED] wrote:
> Thanks Mark for the very useful explanation. How can I get hold of
> this script you mention?

Here you go:

-------------------------

#! /usr/bin/perl
# put into the public domain by Russell Nelson <[EMAIL PROTECTED]>
# NO GUARANTEE AT ALL; support is available for a fee from the author.
#
# Creates maildirs for everyone in /etc/passwd who receives mail.
# Copies all their mail in /var/spool/mail into their maildir.
# Assumes that nothing is trying to modify the mailboxes in /var/spool/mail
#   This assumption could be removed by locking the mailboxes and deleting
#   the mail after moving it.
# version 0.00 - first release to the public.

while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) =
      getpwent()) {
    if (!-e $dir) {
        print "warning: ${name}'s home dir, $dir, doesn't exist (passwd:
$passwd), skipping.\n";
        next;
    }
    $st_uid = (stat($dir))[4];;
    if ($uid != $st_uid) {
        print "warning: $name is $uid, but $dir is owned by $st_uid,
skipping.\n";
        next;
    }
    print "$name\n";
    $spoolname = "$dir/Maildir";
    -d $spoolname || mkdir $spoolname,0700 || die "fatal: mailbox doesn't
exist and can't be created.\n";
    chown ($uid,$gid,$spoolname);
    chdir($spoolname) || die("fatal: unable to chdir to $spoolname.\n");
    -d "tmp" || mkdir("tmp",0700) || die("fatal: unable to make tmp/
subdir\n");
    -d "new" || mkdir("new",0700) || die("fatal: unable to make new/
subdir\n");
    -d "cur" || mkdir("cur",0700) || die("fatal: unable to make cur/
subdir\n");
    chown ($uid,$gid,"tmp","new","cur");

    open(SPOOL, "</var/spool/mail/$name") || next;
    $i = time;
    while(<SPOOL>) {
        if (/^From /) {
            $fn = sprintf("new/%d.$$.mbox", $i);
            open(OUT, ">$fn") || die("fatal: unable to create new
message");;
            chown ($uid,$gid,$fn);
            $i++;
            next;
        }
        s/^>From /From /;
        print OUT || die("fatal: unable to write to new message");
    }
    close(SPOOL);
    close(OUT);
}
endpwent();

-----------------------------


> But as my earlier posting indicated, in this particular case there are
> no lock files (.username) present in /var/spool/mail. I am still at
> square 1. I'll do these changes after sorting out this problem.
> 
>> [EMAIL PROTECTED] wrote:
>>> Use ls -al
>>> and check for the file under the name /var/spool/mail/.username
>> 
>> Yes, it could be that the user's spool file locked while
>> reading/writing new mail data. Usually, mail stored in 'mbox' format
>> will create lock files (very bad, very slow). My suggestion is that
>> you move your mail storage format from 'mbox' to Maildir/.
>> 
>> Maildir/ mail storage format is the same way Eudora stores its mail
>> on a client machine. MS Outlook, Netscape Mail, e.t.c, mimic the
>> 'mbox' format. With Maildir/, each mail is stored as a single file -
>> this means mail can be quickly accessed, and no .lock files are
>> created when the spool file is accessed for read/write i/o. 
>> 
>> If you are interested in this format, there are 3 things you'd need
>> to do: 
>> 
>>      o First, convert all your existing 'mbox' mail to Maildir/. This
>> will read your 'mbox' spool file, and break each
>>        message up into separate files. I have a script that will do this.
>> The script will read all users in the
>>        /etc/passwd file, access their /var/spool/mail/username files and
>> convert each mail into a single file. The script
>>        will then create a ~user/Maildir/ directory in the user's home
>> directory as specified by the 'homedir' variable for
>>        the user in the '/etc/passwd' file.
>> 
>>      o Now that the user's existing mail has taken on a Maildir/ storage
>> format, you will need to tell your MTA to deliver
>>        mail to the user's home directory in Maildir/ format, and not
>> 'mbox' format. From the last time I checked, Postfix
>>        and Exim can do this with some extra configuration. IIRC, Sendmail
>> could be patched to support Maildir/ dropping.
>>        Alternatively, you can call an MDA to do the delivery e.g.
>> maildrop, procmail, smtp.pl, e.t.c.
>> 
>>      o The third thing to do now is to be able to read the mail. Unlike
>> 'mbox' format mail, Maildir/ files aren't just
>>        readable in such a straightforward manner. For those who love
>> Pine, I believe a patch is available to read Maildir/
>>        files; otherwise, Mutt is the most preferred command line MUA for
>> reading/handling Maildir/ files. I am not sure
>>        of the KDE-based MUA's as I haven't tried them, but you could do
>> your experiments. As usual, Google is your friend.
>> 
>>> 
>>> 
>>> On Apr 24, 2004, at 10:16 AM, Lule George William wrote:
>>> 
>>>> Hello all,
>>>> Something strange has just happened. A user has just lost all his
>>>> mails, over 32MB of them!!! When I check /var/spool/mail/username,
>>>> I find that only 12k is left. I am sure he didn't delete them
>>>> because he needs all of them, what do you think happened? Is there
>>>> a chance of retrieving any? System: SuSE Linux 7.2, kernel
>>>> 2.4.4-4GB, 40GB Hard disk and 512 RAM. Neomail is the MUA.
>>>> 
> **********************************************************************
>>>> * *
>>>> Lule George William (Mr)
>>>> Network and Systems Administrator
>>>> Uganda Martyrs University, Nkozi
>>>> P.O. Box 5498 Kampala
>>>> Uganda
>>>> 
>>>> 
>>>> ---------------------------------------------
>>>> This service is hosted on the Infocom network
>>>> http://www.infocom.co.ug
>>>> 
>>>> 
>>> 
>>> ****************                   *****************************
>>> Kiggundu Mukasa                # Computer Network Consultancy###
>>> KYM-NET LTD.                   # Intranets & Internet Solutions#
>>> Plot 80 Kanjokya Street P.O. Box 24284 Kampala, Uganda
>>> Tel:     +256 77 972255
>>>           +256 71 221141
>>> Fax:     +256 31 262122
>>> *****************************************************************
>>> 
>>> 
>>> 
>>> ---------------------------------------------
>>> This service is hosted on the Infocom network
>>> http://www.infocom.co.ug
>> 
>> Regards,
>> 
>> Mark Tinka
>> Technical Manager, Africa Online Swaziland
>> 
>> 
>> 
>> ---------------------------------------------
>> This service is hosted on the Infocom network
>> http://www.infocom.co.ug 
>> 
>> 
> 
> ************************************************************************
> Lule George William (Mr)
> Network and Systems Administrator
> Uganda Martyrs University, Nkozi
> P.O. Box 5498 Kampala
> Uganda
> 
> 
> ---------------------------------------------
> This service is hosted on the Infocom network http://www.infocom.co.ug

Regards,

Mark Tinka
Technical Manager, Africa Online Swaziland



---------------------------------------------
This service is hosted on the Infocom network
http://www.infocom.co.ug

Reply via email to