Reading spam dir with PHP? {Scanned by HJMS}

Furnish, Trever G TGFurnish at HERFF-JONES.COM
Thu Oct 2 21:49:51 IST 2003

Hmmm... I guess there are several routes you could take, including sudo.

But MailWatch is pretty straight-forward to install and it already offers
the functionality you want to create.

The approach taken by MailWatch was to run a cronjob every minute as root to
recursively chown/chmod the directory.

I think a combo of this and sudo might be better - sudo alone would be sort
of annoying because everything sudo does gets logged.  You could instead
check to see whether you can access the files you want (since that will
happen rarely) and if not, then use sudo to run a command to modify their
ownership/permissions and attempt the access again.  That way the
chown/chmod would only run when needed and you wouldn't be creating an
effectively suid root script that takes input from the web.

Your sudo script could be simply:
chown -R root:apache /var/spool/MailScanner/quarantine
chmod -R g+rwx /var/spool/MailScanner/quarantine
exit 0

And your php page would only run it if it failed to open a file.  If the
failure recurs after running the sudo script, then it's not related to

Having started to play with MailWatch though I'm very impressed with it and
would recommend trying it first.


> -----Original Message-----
> From: Max Kipness [mailto:mkipness at GENIANT.COM]
> Sent: Thursday, October 02, 2003 3:37 PM
> Subject: Reading spam dir with PHP? {Scanned by HJMS}
> Hello,
> Sorry if I'm off topic. This may be more of a PHP or general
> linux question.
> I'm trying to write a php page that reads the ../spam dir.
> I'm planning on having the page read each q* file and parse
> the From:, To: and Subject: lines and then have a button for
> each message that basically copies the q* and d* files to the
> sendmail queue.
> At this point I'm trying to figure out the best way to get
> access to that directory structure as user Apache. All of the
> dir/files under ./var/spool/MailScanner have rw for root
> only. Is the answer sudo?
> Thanks,
> Max

More information about the MailScanner mailing list