-
- if (spool_mbox_ok) {
-
- spool_mbox_ok = 0;
-
- if (!no_mbox_unspool) {
- uschar mbox_path[1024];
- uschar file_path[1024];
- int n;
- struct dirent *entry;
- DIR *tempdir;
-
- snprintf(CS mbox_path, 1024, "%s/scan/%s", spool_directory, spooled_message_id);
-
- tempdir = opendir(CS mbox_path);
- /* loop thru dir & delete entries */
- n = 0;
- do {
- entry = readdir(tempdir);
- if (entry == NULL) break;
- snprintf(CS file_path, 1024,"%s/scan/%s/%s", spool_directory, spooled_message_id, entry->d_name);
- if ( (Ustrcmp(entry->d_name,"..") != 0) && (Ustrcmp(entry->d_name,".") != 0) ) {
- debug_printf("unspool_mbox(): unlinking '%s'\n", file_path);
- n = unlink(CS file_path);
- };
- } while (n > -1);
-
- closedir(tempdir);
-
- /* remove directory */
- n = rmdir(CS mbox_path);
+
+ if (spool_mbox_ok && !no_mbox_unspool) {
+ uschar *mbox_path;
+ uschar *file_path;
+ int n;
+ struct dirent *entry;
+ DIR *tempdir;
+
+ mbox_path = string_sprintf("%s/scan/%s", spool_directory, spooled_message_id);
+
+ tempdir = opendir(CS mbox_path);
+ if (!tempdir) {
+ debug_printf("Unable to opendir(%s): %s\n", mbox_path, strerror(errno));
+ /* Just in case we still can: */
+ rmdir(CS mbox_path);
+ return;
+ }
+ /* loop thru dir & delete entries */
+ while((entry = readdir(tempdir)) != NULL) {
+ uschar *name = US entry->d_name;
+ if (Ustrcmp(name, US".") == 0 || Ustrcmp(name, US"..") == 0) continue;
+
+ file_path = string_sprintf("%s/%s", mbox_path, name);
+ debug_printf("unspool_mbox(): unlinking '%s'\n", file_path);
+ n = unlink(CS file_path);