+int ignore_entry(const char *name) {
+ return
+ strcmp(name, ".") == 0 ||
+ strcmp(name, "..") == 0 ||
+ (name[0] == '.' && name[1] != '/');
+}
+
+void process_dir(const char *dir_name) {
+ DIR *dir;
+ struct dirent *dir_e;
+ struct stat sb;
+ char subname[PATH_MAX + 1];
+
+ if(lstat(dir_name, &sb) != 0) {
+ fprintf(stderr, "mymail: Can not stat \"%s\": %s\n", dir_name, strerror(errno));
+ exit(EXIT_FAILURE);
+ } else {
+ }
+
+ if(S_ISLNK(sb.st_mode)) {
+ return;
+ }
+
+ dir = opendir(dir_name);
+
+ if(dir) {
+ printf("Processing directory '%s'.\n", dir_name);
+ while((dir_e = readdir(dir))) {
+ if(!ignore_entry(dir_e->d_name)) {
+ snprintf(subname, PATH_MAX, "%s/%s", dir_name, dir_e->d_name);
+ process_dir(subname);
+ }
+ }
+ closedir(dir);
+ } else {
+ if(S_ISREG(sb.st_mode)) {
+ printf("Processing regular file '%s'.\n", dir_name);
+ read_file(dir_name);
+ }
+ }
+}
+