]> diplodocus.org Git - minc/commitdiff
(getfiles): New function, returns a list of all entries in a
authorepg <>
Fri, 30 Aug 2002 00:27:37 +0000 (00:27 +0000)
committerepg <>
Fri, 30 Aug 2002 00:27:37 +0000 (00:27 +0000)
directory.

(MAIN): Call getfiles instead of using glob.

minc

diff --git a/minc b/minc
index d1fe222..da96908 100755 (executable)
--- a/minc
+++ b/minc
@@ -349,6 +349,34 @@ sub get_headers {
     return %headers;
 }
 
+sub getfiles {
+    my $dir = shift;
+    my @result;
+
+    if (not opendir(DIR, $dir)) {
+        err(&EX_TEMPFAIL, "Failed opendir($dir)");
+    }
+
+    # Initialize $! to 0 (success) because stupid stupid Perl provides
+    # no way to distinguish an error from an empty directory; that
+    # means setting $! to 0 and testing it afterwards is the only way
+    # to detect an error.  Real Programmers don't handle errors,
+    # right?  >sigh<
+    $! = 0;
+    @result = grep {
+        ($_ ne '.' and $_ ne '..')
+          and $_ = "$MAILDIR/new/$_"
+      } readdir(DIR);
+
+    if ($! != 0) {
+        err(&EX_TEMPFAIL, "Failed readdir($dir)");
+    }
+
+    closedir(DIR);
+
+    return @result;
+}
+
 \f
 ###############################################################################
 # Spam handling
@@ -492,7 +520,7 @@ MAIN: {
         exit(&EX_OK);
     }
 
-    @msglist = kill_spam(glob("$MAILDIR/new/*"));
+    @msglist = kill_spam(getfiles("$MAILDIR/new"));
 
     if (not $spamonly) {
         filter_mail(@msglist);