You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smtp_date.rl 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. %%{
  2. machine smtp_date;
  3. # SMTP date spec
  4. # Obtained from: http://tools.ietf.org/html/rfc5322#section_3.3
  5. action Day_Start {
  6. tmp = p;
  7. }
  8. action Day_End {
  9. if (p > tmp) {
  10. gulong n;
  11. if (rspamd_strtoul (tmp, p - tmp, &n)) {
  12. if (n > 0 && n <= 31) {
  13. tm.tm_mday = n;
  14. }
  15. else {
  16. fbreak;
  17. }
  18. }
  19. }
  20. }
  21. action Month_End {
  22. }
  23. action Year_Start {
  24. tmp = p;
  25. }
  26. action Year_End {
  27. if (p > tmp) {
  28. gulong n;
  29. if (rspamd_strtoul (tmp, p - tmp, &n)) {
  30. if (n < 1000) {
  31. if (n < 50) {
  32. tm.tm_year = n - 1900 + 2000;
  33. }
  34. else {
  35. tm.tm_year = n;
  36. }
  37. }
  38. else {
  39. tm.tm_year = n - 1900;
  40. }
  41. }
  42. }
  43. }
  44. action Hour_Start {
  45. tmp = p;
  46. }
  47. action Hour_End {
  48. if (p > tmp) {
  49. gulong n;
  50. if (rspamd_strtoul (tmp, p - tmp, &n)) {
  51. if (n < 24) {
  52. tm.tm_hour = n;
  53. }
  54. else {
  55. fbreak;
  56. }
  57. }
  58. }
  59. else {
  60. fbreak;
  61. }
  62. }
  63. action Minute_Start {
  64. tmp = p;
  65. }
  66. action Minute_End {
  67. if (p > tmp) {
  68. gulong n;
  69. if (rspamd_strtoul (tmp, p - tmp, &n)) {
  70. if (n < 60) {
  71. tm.tm_min = n;
  72. }
  73. else {
  74. fbreak;
  75. }
  76. }
  77. }
  78. else {
  79. fbreak;
  80. }
  81. }
  82. action Second_Start {
  83. tmp = p;
  84. }
  85. action Second_End {
  86. if (p > tmp) {
  87. gulong n;
  88. if (rspamd_strtoul (tmp, p - tmp, &n)) {
  89. if (n <= 60) { /* Leap second */
  90. tm.tm_sec = n;
  91. }
  92. else {
  93. fbreak;
  94. }
  95. }
  96. }
  97. else {
  98. fbreak;
  99. }
  100. }
  101. action TZ_Sign {
  102. tmp = p;
  103. }
  104. action TZ_Offset_Start {
  105. }
  106. action TZ_Offset_End {
  107. if (p > tmp) {
  108. rspamd_strtoul (tmp, p - tmp, (gulong *)&tz);
  109. if (*(tmp - 1) == '-') {
  110. tz = -(tz);
  111. }
  112. }
  113. }
  114. action Obs_Zone_End {
  115. }
  116. action DT_End {
  117. }
  118. # Specific actions
  119. # Months
  120. action Month_Jan {
  121. tm.tm_mon = 0;
  122. }
  123. action Month_Feb {
  124. tm.tm_mon = 1;
  125. }
  126. action Month_Mar {
  127. tm.tm_mon = 2;
  128. }
  129. action Month_Apr {
  130. tm.tm_mon = 3;
  131. }
  132. action Month_May {
  133. tm.tm_mon = 4;
  134. }
  135. action Month_Jun {
  136. tm.tm_mon = 5;
  137. }
  138. action Month_Jul {
  139. tm.tm_mon = 6;
  140. }
  141. action Month_Aug {
  142. tm.tm_mon = 7;
  143. }
  144. action Month_Sep {
  145. tm.tm_mon = 8;
  146. }
  147. action Month_Oct {
  148. tm.tm_mon = 9;
  149. }
  150. action Month_Nov {
  151. tm.tm_mon = 10;
  152. }
  153. action Month_Dec {
  154. tm.tm_mon = 11;
  155. }
  156. # Obsoleted timezones
  157. action TZ_UT {
  158. tz = 0;
  159. }
  160. action TZ_GMT {
  161. tz = 0;
  162. }
  163. action TZ_EST {
  164. tz = -500;
  165. }
  166. action TZ_EDT {
  167. tz = -400;
  168. }
  169. action TZ_CST {
  170. tz = -600;
  171. }
  172. action TZ_CDT {
  173. tz = -500;
  174. }
  175. action TZ_MST {
  176. tz = -700;
  177. }
  178. action TZ_MDT {
  179. tz = -600;
  180. }
  181. action TZ_PST {
  182. tz = -800;
  183. }
  184. action TZ_PDT {
  185. tz = -700;
  186. }
  187. prepush {
  188. if (top >= st_storage.size) {
  189. st_storage.size = (top + 1) * 2;
  190. st_storage.data = realloc (st_storage.data, st_storage.size * sizeof (int));
  191. g_assert (st_storage.data != NULL);
  192. stack = st_storage.data;
  193. }
  194. }
  195. ccontent = ctext | FWS | '(' @{ fcall balanced_ccontent; };
  196. balanced_ccontent := ccontent* ')' @{ fret; };
  197. comment = "(" (FWS? ccontent)* FWS? ")";
  198. CFWS = ((FWS? comment)+ FWS?) | FWS;
  199. digit_2 = digit{2};
  200. digit_4 = digit{4};
  201. day_name = "Mon" | "Tue" | "Wed" | "Thu" |
  202. "Fri" | "Sat" | "Sun";
  203. day_of_week = FWS? day_name;
  204. day = FWS? digit{1,2} >Day_Start %Day_End FWS;
  205. month = "Jan" %Month_Jan | "Feb" %Month_Feb | "Mar" %Month_Mar | "Apr" %Month_Apr |
  206. "May" %Month_May | "Jun" %Month_Jun | "Jul" %Month_Jul | "Aug" %Month_Aug |
  207. "Sep" %Month_Sep | "Oct" %Month_Oct | "Nov" %Month_Nov | "Dec" %Month_Dec;
  208. year = FWS digit{2,4} >Year_Start %Year_End FWS;
  209. date = day month %Month_End year;
  210. hour = digit_2;
  211. minute = digit_2;
  212. second = digit_2;
  213. time_of_day = hour >Hour_Start %Hour_End ":" minute >Minute_Start %Minute_End (":" second >Second_Start %Second_End )?;
  214. zone = ("+" | "-") %TZ_Sign digit_4 >TZ_Offset_Start %TZ_Offset_End;
  215. obs_zone = "UT" %TZ_UT | "GMT" %TZ_GMT |
  216. "EST" %TZ_EST | "EDT" %TZ_EDT |
  217. "CST" %TZ_CST | "CDT" %TZ_CDT |
  218. "MST" %TZ_MST | "MDT" %TZ_MDT |
  219. "PST" %TZ_PST | "PDT" %TZ_PDT |
  220. [a-iA-I] | [k-zK-Z];
  221. time = time_of_day %DT_End FWS (zone | obs_zone %Obs_Zone_End) FWS*;
  222. date_time = (day_of_week ",")? date time CFWS?;
  223. }%%