]> git.pld-linux.org Git - packages/epic4.git/blame - epic4-maildir.patch
- s/^Terminal=0/Terminal=false/ s/^Terminal=1/Terminal=true/ to conform
[packages/epic4.git] / epic4-maildir.patch
CommitLineData
74c8ff23 1diff -urN epic4-1.0.1.orig/source/mail.c epic4-1.0.1/source/mail.c
2--- epic4-1.0.1.orig/source/mail.c Tue Dec 5 01:11:57 2000
3+++ epic4-1.0.1/source/mail.c Sun Apr 14 12:28:16 2002
4@@ -5,7 +5,10 @@
5 * Written by Jeremy Nelson
6 * Copyright 1996 EPIC Software Labs
7 */
8-
9+/*
10+ * Maildirs are also supported.
11+ * Written by Olgierd Pieczul <wojrus@pld.org.pl>
12+ */
13 #include "irc.h"
14 #include "mail.h"
15 #include "lastlog.h"
16@@ -18,7 +21,8 @@
17 #endif
18 #include <sys/stat.h>
19 #include <utime.h>
20-
21+#include <stdio.h>
22+#include <dirent.h>
23 static char *mail_path = (char *) 0;
24
25 /*
26@@ -31,7 +35,6 @@
27 static time_t old_stat = 0;
28 struct stat sb;
29 struct stat * stat_buf;
30-
31 if (ptr)
32 stat_buf = (struct stat *)ptr;
33 else
34@@ -51,9 +54,14 @@
35 if (!(tmp_mail_path = getenv("MAIL")))
36 tmp_mail_path = path_search(username, mail_path_list);
37
38- if (tmp_mail_path)
39+ if (tmp_mail_path) {
40 mail_path = m_strdup(tmp_mail_path);
41-
42+ if (stat(mail_path, stat_buf) == -1)
43+ return 0;
44+ /* Check whether mailbox is a directory (Maildir) and add "new/" suffix */
45+ if ((stat_buf->st_mode & S_IFMT) == S_IFDIR)
46+ mail_path = m_2dup(mail_path, "/new/");
47+ }
48 else
49 mail_path = m_strdup("<unknown>");
50 }
51@@ -70,22 +78,35 @@
52 {
53 old_stat = stat_buf->st_ctime;
54 if (stat_buf->st_size)
55- return 2;
56+ return 2;
57 }
58
59 /*
60 * If there is something in the mailbox
61 */
62- if (stat_buf->st_size)
63- return 1;
64-
65+ if (stat_buf->st_size) {
66+ /* if maildir - how many files */
67+ if ((stat_buf->st_mode & S_IFMT) == S_IFDIR) {
68+ DIR *dir;
69+ int i = -2;
70+ if ((dir = opendir(mail_path)) == NULL)
71+ return 0;
72+ while (readdir(dir) != NULL)
73+ i++;
74+ closedir(dir);
75+ if (i > 0)
76+ return 1;
77+ else
78+ return 0;
79+ }
80+ return 1;
81+ }
82 /*
83 * The mailbox is empty.
84 */
85 return 0;
86 }
87
88-
89 /*
90 * check_mail: report on status of inbox.
91 *
92@@ -142,8 +163,10 @@
93 case 3:
94 {
95 FILE * mail;
96+ DIR * dir;
97 char buffer[255];
98 int count = 0;
99+
100 static int old_count = 0;
101 static char ret_str[12];
102 struct utimbuf ts;
103@@ -152,34 +175,43 @@
104 {
105 case 2:
106 {
107- if (!(mail = fopen(mail_path, "r")))
108- return NULL;
109-
110- while (fgets(buffer, 254, mail))
111- if (!strncmp("From ", buffer, 5))
112- count++;
113-
114- fclose(mail);
115-
116- if (state == 3)
117+ /* if maildir */
118+ if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
119+ if ((dir = opendir(mail_path)) == NULL)
120+ return NULL;
121+ while (readdir(dir) != NULL)
122+ count++;
123+ closedir(dir);
124+ count -= 2;
125+ }
126+ else
127+ {
128+ if (!(mail = fopen(mail_path, "r")))
129+ return NULL;
130+
131+ while (fgets(buffer, 254, mail))
132+ if (!strncmp("From ", buffer, 5))
133+ count++;
134+ fclose(mail);
135+ }
136+ if (state == 3)
137 {
138- /* XXX Ew. Evil. Gross. */
139- ts.actime = stat_buf.st_atime;
140- ts.modtime = stat_buf.st_mtime;
141- utime(mail_path, &ts); /* XXX Ick. Gross */
142+ /* XXX Ew. Evil. Gross. */
143+ ts.actime = stat_buf.st_atime;
144+ ts.modtime = stat_buf.st_mtime;
145+ utime(mail_path, &ts); /* XXX Ick. Gross */
146 }
147-
148- if (count > old_count)
149- {
150- if (do_hook(MAIL_LIST, "%d %d",
151- count - old_count, count))
152- {
153- int lastlog_level =
154+ if (count > old_count)
155+ {
156+ if (do_hook(MAIL_LIST, "%d %d",
157+ count - old_count, count))
158+ {
159+ int lastlog_level =
160 set_lastlog_msg_level(LOG_CRAP);
161 say("You have new email.");
162 set_lastlog_msg_level(lastlog_level);
163 }
164- }
165+ }
166
167 old_count = count;
168 sprintf(ret_str, "%d", old_count);
This page took 0.100765 seconds and 4 git commands to generate.