Commit 749eff46 749eff466fc8e040e20b1073ca4acc2b1c7ae240 by Sergey Poznyakoff

(maildir_message_cmp): Compare the

rest of filenames if the timestamps are equal
1 parent 8e0d7f56
...@@ -134,15 +134,43 @@ info_to_flags (char *buf) ...@@ -134,15 +134,43 @@ info_to_flags (char *buf)
134 static int 134 static int
135 maildir_message_cmp (struct _amd_message *a, struct _amd_message *b) 135 maildir_message_cmp (struct _amd_message *a, struct _amd_message *b)
136 { 136 {
137 char *name_a, *name_b;
137 unsigned long na = strtoul (((struct _maildir_message *) a)->file_name, 138 unsigned long na = strtoul (((struct _maildir_message *) a)->file_name,
138 NULL, 10); 139 &name_a, 10);
139 unsigned long nb = strtoul (((struct _maildir_message *) b)->file_name, 140 unsigned long nb = strtoul (((struct _maildir_message *) b)->file_name,
140 NULL, 10); 141 &name_b, 10);
142 int rc;
143
141 if (na > nb) 144 if (na > nb)
142 return 1; 145 return 1;
143 if (na < nb) 146 if (na < nb)
144 return -1; 147 return -1;
145 return 0; 148
149 /* If timestamps are equal, compare rests of the filenames up to the
150 info marker */
151
152 if (name_a && !name_b)
153 return 1;
154 else if (!name_a)
155 {
156 if (name_b)
157 return -1;
158 else
159 return 0;
160 }
161
162 for (; *name_a && *name_a != ':' && *name_b && *name_b != ':';
163 name_a++, name_b++)
164 if ((rc = (*name_a - *name_b)))
165 return rc;
166
167 if (*name_a == ':' && *name_b == ':')
168 {
169 name_a++;
170 name_b++;
171 }
172
173 return *name_a - *name_b;
146 } 174 }
147 175
148 void 176 void
......