read_content_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package smtp_server
  2. import (
  3. "bytes"
  4. log "github.com/sirupsen/logrus"
  5. "net"
  6. "net/netip"
  7. "os"
  8. "pmail/config"
  9. "pmail/db"
  10. parsemail2 "pmail/dto/parsemail"
  11. "pmail/hooks"
  12. "pmail/session"
  13. "pmail/utils/context"
  14. "testing"
  15. "time"
  16. )
  17. func testInit() {
  18. // 设置日志格式为json格式
  19. //log.SetFormatter(&log.JSONFormatter{})
  20. log.SetReportCaller(true)
  21. log.SetFormatter(&log.TextFormatter{
  22. //以下设置只是为了使输出更美观
  23. DisableColors: true,
  24. TimestampFormat: "2006-01-02 15:03:04",
  25. })
  26. // 设置将日志输出到标准输出(默认的输出为stderr,标准错误)
  27. // 日志消息输出可以是任意的io.writer类型
  28. log.SetOutput(os.Stdout)
  29. // 设置日志级别为warn以上
  30. log.SetLevel(log.ErrorLevel)
  31. var cst, _ = time.LoadLocation("Asia/Shanghai")
  32. time.Local = cst
  33. config.Init()
  34. config.Instance.DkimPrivateKeyPath = "../config/dkim/dkim.priv"
  35. config.Instance.DbType = config.DBTypeSQLite
  36. config.Instance.DbDSN = "../config/pmail_temp.db"
  37. parsemail2.Init()
  38. db.Init()
  39. session.Init()
  40. hooks.Init("dev")
  41. }
  42. func TestPmailEmail(t *testing.T) {
  43. testInit()
  44. emailData := `DKIM-Signature: a=rsa-sha256; bh=x7Rh+N2y2K9exccEAyKCTAGDgYKfnLZpMWc25ug5Ny4=;
  45. c=simple/simple; d=domain.com;
  46. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693831868;
  47. v=1;
  48. b=1PZEupYvSMtGyYx42b4G65YbdnRj4y2QFo9kS7GXiTVhUM5EYzJhZzknwRMN5RL5aFY26W4E
  49. DmzJ85XvPPvrDtnU/B4jkc5xthE+KEsb1Go8HcL8WQqwvsE9brepeA0t0RiPnA/x7dbTo3u72SG
  50. WqtviWbJH5lPFc9PkSbEPFtc=
  51. Content-Type: multipart/mixed;
  52. boundary=3c13260efb7bd8bad8315c21215489fe283f36cdf82813674f6e11215f6c
  53. Mime-Version: 1.0
  54. Subject: =?utf-8?q?=E6=8F=92=E4=BB=B6=E6=B5=8B=E8=AF=95?=
  55. To: =?utf-8?q?=E5=90=8D?= <ok@jinnrry.com>
  56. From: =?utf-8?q?=E5=8F=91=E9=80=81=E4=BA=BA?= <j@jinnrry.com>
  57. Date: Mon, 04 Sep 2023 20:51:08 +0800
  58. --3c13260efb7bd8bad8315c21215489fe283f36cdf82813674f6e11215f6c
  59. Content-Type: multipart/alternative;
  60. boundary=9ebf2f3c4f97c51dd9a285ae28a54d2d0d84aa6d0ad28b76547e2096bb66
  61. --9ebf2f3c4f97c51dd9a285ae28a54d2d0d84aa6d0ad28b76547e2096bb66
  62. Content-Transfer-Encoding: quoted-printable
  63. Content-Disposition: inline
  64. Content-Type: text/plain
  65. =E8=BF=99=E6=98=AFText
  66. --9ebf2f3c4f97c51dd9a285ae28a54d2d0d84aa6d0ad28b76547e2096bb66
  67. Content-Transfer-Encoding: quoted-printable
  68. Content-Disposition: inline
  69. Content-Type: text/html
  70. <div>=E8=BF=99=E6=98=AFHtml</div>
  71. --9ebf2f3c4f97c51dd9a285ae28a54d2d0d84aa6d0ad28b76547e2096bb66--
  72. --3c13260efb7bd8bad8315c21215489fe283f36cdf82813674f6e11215f6c--
  73. `
  74. s := Session{
  75. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  76. Ctx: &context.Context{
  77. UserID: 0,
  78. UserName: "",
  79. UserAccount: "",
  80. },
  81. To: []string{"ok@jinnrry.com"},
  82. }
  83. s.Data(bytes.NewReader([]byte(emailData)))
  84. }
  85. func TestRuleForward(t *testing.T) {
  86. testInit()
  87. forwardEmail := `DKIM-Signature: a=rsa-sha256; bh=bpOshF+iimuqAQijVxqkH6gPpWf8A+Ih30/tMjgEgS0=;
  88. c=simple/simple; d=jinnrry.com;
  89. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992640;
  90. v=1;
  91. b=XiOgYL9iGrkuYzXBAf7DSO0sRbFr6aPOE4VikmselNKEF1UTjMPdiqpeHyx/i6BOQlJWWZEC
  92. PzceHTDFIStcZE6a5Sc1nh8Fis+gRkrheBO/zK/P5P/euK+0Fj5+0T82keNTSCgo1ZtEIubaNR0
  93. JvkwJ2ZC9g8xV6Yiq+ZhRriT8lZ6zeI55PPEFJIzFgZ7xDshDgx5E7J1xRXQqcEMV1rgVq04d3c
  94. 6wjU+LLtghmgtUToRp3ASn6DhVO+Bbc4QkmcQ/StQH3681+1GVMHvQSBhSSymSRA71SikE2u3a1
  95. JnvbOP9fThP7h+6oFEIRuF7MwDb3JWY5BXiFFKCkecdFg==
  96. Content-Type: multipart/mixed;
  97. boundary=8e9d5abb6bdac11b8d7d6e13280af1a87d12b904a59368d6e852b0a4ce3e
  98. Mime-Version: 1.0
  99. Subject: forward
  100. To: <t@jiangwei.one>
  101. From: "i" <i@jinnrry.com>
  102. Date: Wed, 06 Sep 2023 17:30:40 +0800
  103. --8e9d5abb6bdac11b8d7d6e13280af1a87d12b904a59368d6e852b0a4ce3e
  104. Content-Type: multipart/alternative;
  105. boundary=a62ae91c159ea22e8196d57d344626eb00d1ddfa9c5064a39b01588aa992
  106. --a62ae91c159ea22e8196d57d344626eb00d1ddfa9c5064a39b01588aa992
  107. Content-Transfer-Encoding: quoted-printable
  108. Content-Disposition: inline
  109. Content-Type: text/plain
  110. hello pls Forward the email.
  111. --a62ae91c159ea22e8196d57d344626eb00d1ddfa9c5064a39b01588aa992
  112. Content-Transfer-Encoding: quoted-printable
  113. Content-Disposition: inline
  114. Content-Type: text/html
  115. <p>hello pls Forward the email.</p>
  116. --a62ae91c159ea22e8196d57d344626eb00d1ddfa9c5064a39b01588aa992--
  117. --8e9d5abb6bdac11b8d7d6e13280af1a87d12b904a59368d6e852b0a4ce3e--`
  118. readEmail := `DKIM-Signature: a=rsa-sha256; bh=JcCDj6edb1bAwRbcFZ63plFZOeB5AdGWLE/PQ2FQ1Tc=;
  119. c=simple/simple; d=jinnrry.com;
  120. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992600;
  121. v=1;
  122. b=rwlqSkDFKYH42pA1jsajemaw+4YdeLHPeqV4mLQrRdihgma1VSvXl5CEOur/KuwQuUarr2cu
  123. SntWrHE6+RnDaQcPEHbkgoMjEJw5+VPwkIvE6VSlMIB7jg93mGzvN2yjheWTePZ+cVPjOaIrgir
  124. wiT24hkrTHp+ONT8XoS0sDuY+ieyBZp/GCv/YvgE4t0JEkNozMAVWotrXxaICDzZoWP3NNmKLqg
  125. 6He6zwWAl51r3W5R5weGBi6A/FqlHgHZGroXnNi+wolDuN6pQiVAJ7MZ6hboPCbCCRrBQDTdor5
  126. wEI2+MwlJ/d2f17wxoGmluCewbeYttuVcpUOVwACJKw3g==
  127. Content-Type: multipart/mixed;
  128. boundary=9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3
  129. Mime-Version: 1.0
  130. Subject: read
  131. To: <t@jiangwei.one>
  132. From: "i" <i@jinnrry.com>
  133. Date: Wed, 06 Sep 2023 17:30:00 +0800
  134. --9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3
  135. Content-Type: multipart/alternative;
  136. boundary=54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  137. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  138. Content-Transfer-Encoding: quoted-printable
  139. Content-Disposition: inline
  140. Content-Type: text/plain
  141. 12 aRead 1sadf
  142. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  143. Content-Transfer-Encoding: quoted-printable
  144. Content-Disposition: inline
  145. Content-Type: text/html
  146. <p>12 aRead 1sadf</p>
  147. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884--
  148. --9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3--`
  149. moveEmail := `DKIM-Signature: a=rsa-sha256; bh=YQfG/wlHGhky6FNmpIwgDYDOc/uyivdBv+9S02Z04xY=;
  150. c=simple/simple; d=jinnrry.com;
  151. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992542;
  152. v=1;
  153. b=IhxswOCq8I7CmCas1EMp+n8loR7illqlF0IJC6eN1+OLjI/E5BPzpP4HWkyqaAkd0Vn9i+Bn
  154. MVb5kNHZ2S7qt0rqAAc6Atc0i9WpLEI3Cng+VDn+difcMZlJSAkhLLn2sUsS4Fzqqo3Cbw62qSO
  155. TgnWRmlj9aM+5xfGcl/76WOvQQpahJbGg6Go51kFMeHVom/VeGKIgFBCeMe37T/LS03c3pAV8gA
  156. i6Zy3GYE57W/qU3oCzaGeS3n5zom/i74H4VipiVIMX/OBNYhdHWrP8vyjvzLFpJlXp6RvzcRl0P
  157. ytyiCZfE8G7fAFntp20LW70Y5Xgqqczk1jR578UDczVoA==
  158. Content-Type: multipart/mixed;
  159. boundary=c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d
  160. Mime-Version: 1.0
  161. Subject: Move
  162. To: <t@jiangwei.one>
  163. From: "i" <i@jinnrry.com>
  164. Date: Wed, 06 Sep 2023 17:29:02 +0800
  165. --c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d
  166. Content-Type: multipart/alternative;
  167. boundary=a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  168. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  169. Content-Transfer-Encoding: quoted-printable
  170. Content-Disposition: inline
  171. Content-Type: text/plain
  172. MOVE move Move
  173. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  174. Content-Transfer-Encoding: quoted-printable
  175. Content-Disposition: inline
  176. Content-Type: text/html
  177. <p>MOVE move Move</p>
  178. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966--
  179. --c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d--`
  180. deleteEmail := `DKIM-Signature: a=rsa-sha256; bh=dNtHGqd1NbRj0WSwrJmPsqAcAy3h/4kZK2HFQ0Asld8=;
  181. c=simple/simple; d=jinnrry.com;
  182. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992495;
  183. v=1;
  184. b=QllU8lqGdoOMaGYp8d13oWytb7+RebqKjq4y8Rs/kOeQxoE8dSEVliK3eBiXidsNTdDtkTqf
  185. eiwjyRBK92NVCYprdJqLbu9qZ39BC2lk3NXttTSJ1+1ZZ/bGtIW5JIYn2pToED0MqVVkxGFUtl+
  186. qFmc4mWo5a4Mbij7xaAB3uJtHpBDt7q4Ovr2hiMetQv7YrhZvCt/xrH8Q9YzZ6xzFUL5ekW40eH
  187. oWElU1GyVBHWCKh31aweyhA+1XLPYojjREQYd4svRqTbSFSsBqFwFIUGdnyJh2WgmF8eucmttAw
  188. oRhgzyZkHL1jAskKFBpO10SDReyk50Cvc+0kSLj+QcUpg==
  189. Content-Type: multipart/mixed;
  190. boundary=bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3
  191. Mime-Version: 1.0
  192. Subject: test
  193. To: <t@jiangwei.one>
  194. From: "i" <i@jinnrry.com>
  195. Date: Wed, 06 Sep 2023 17:28:15 +0800
  196. --bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3
  197. Content-Type: multipart/alternative;
  198. boundary=7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  199. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  200. Content-Transfer-Encoding: quoted-printable
  201. Content-Disposition: inline
  202. Content-Type: text/plain
  203. Delete
  204. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  205. Content-Transfer-Encoding: quoted-printable
  206. Content-Disposition: inline
  207. Content-Type: text/html
  208. <p>Delete</p>
  209. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04--
  210. --bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3--`
  211. s := Session{
  212. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  213. Ctx: &context.Context{},
  214. }
  215. s.Data(bytes.NewReader([]byte(deleteEmail)))
  216. s.Data(bytes.NewReader([]byte(readEmail)))
  217. s.Data(bytes.NewReader([]byte(forwardEmail)))
  218. s.Data(bytes.NewReader([]byte(moveEmail)))
  219. }
  220. func TestRuleRead(t *testing.T) {
  221. testInit()
  222. readEmail := `DKIM-Signature: a=rsa-sha256; bh=JcCDj6edb1bAwRbcFZ63plFZOeB5AdGWLE/PQ2FQ1Tc=;
  223. c=simple/simple; d=jinnrry.com;
  224. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992600;
  225. v=1;
  226. b=rwlqSkDFKYH42pA1jsajemaw+4YdeLHPeqV4mLQrRdihgma1VSvXl5CEOur/KuwQuUarr2cu
  227. SntWrHE6+RnDaQcPEHbkgoMjEJw5+VPwkIvE6VSlMIB7jg93mGzvN2yjheWTePZ+cVPjOaIrgir
  228. wiT24hkrTHp+ONT8XoS0sDuY+ieyBZp/GCv/YvgE4t0JEkNozMAVWotrXxaICDzZoWP3NNmKLqg
  229. 6He6zwWAl51r3W5R5weGBi6A/FqlHgHZGroXnNi+wolDuN6pQiVAJ7MZ6hboPCbCCRrBQDTdor5
  230. wEI2+MwlJ/d2f17wxoGmluCewbeYttuVcpUOVwACJKw3g==
  231. Content-Type: multipart/mixed;
  232. boundary=9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3
  233. Mime-Version: 1.0
  234. Subject: read
  235. To: <t@jiangwei.one>
  236. From: "i" <i@jinnrry.com>
  237. Date: Wed, 06 Sep 2023 17:30:00 +0800
  238. --9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3
  239. Content-Type: multipart/alternative;
  240. boundary=54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  241. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  242. Content-Transfer-Encoding: quoted-printable
  243. Content-Disposition: inline
  244. Content-Type: text/plain
  245. 12 aRead 1sadf
  246. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884
  247. Content-Transfer-Encoding: quoted-printable
  248. Content-Disposition: inline
  249. Content-Type: text/html
  250. <p>12 aRead 1sadf</p>
  251. --54a95f3429f3cdb342383db10293780bed341f8dc20d2f876eb0853e3884--
  252. --9e33a130a8a976102a93e296d6408d228e151f7841ca9ee0d777234fd6f3--`
  253. s := Session{
  254. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  255. Ctx: &context.Context{},
  256. }
  257. s.Data(bytes.NewReader([]byte(readEmail)))
  258. }
  259. func TestRuleDelete(t *testing.T) {
  260. testInit()
  261. deleteEmail := `DKIM-Signature: a=rsa-sha256; bh=dNtHGqd1NbRj0WSwrJmPsqAcAy3h/4kZK2HFQ0Asld8=;
  262. c=simple/simple; d=jinnrry.com;
  263. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992495;
  264. v=1;
  265. b=QllU8lqGdoOMaGYp8d13oWytb7+RebqKjq4y8Rs/kOeQxoE8dSEVliK3eBiXidsNTdDtkTqf
  266. eiwjyRBK92NVCYprdJqLbu9qZ39BC2lk3NXttTSJ1+1ZZ/bGtIW5JIYn2pToED0MqVVkxGFUtl+
  267. qFmc4mWo5a4Mbij7xaAB3uJtHpBDt7q4Ovr2hiMetQv7YrhZvCt/xrH8Q9YzZ6xzFUL5ekW40eH
  268. oWElU1GyVBHWCKh31aweyhA+1XLPYojjREQYd4svRqTbSFSsBqFwFIUGdnyJh2WgmF8eucmttAw
  269. oRhgzyZkHL1jAskKFBpO10SDReyk50Cvc+0kSLj+QcUpg==
  270. Content-Type: multipart/mixed;
  271. boundary=bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3
  272. Mime-Version: 1.0
  273. Subject: test
  274. To: <t@jiangwei.one>
  275. From: "i" <i@jinnrry.com>
  276. Date: Wed, 06 Sep 2023 17:28:15 +0800
  277. --bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3
  278. Content-Type: multipart/alternative;
  279. boundary=7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  280. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  281. Content-Transfer-Encoding: quoted-printable
  282. Content-Disposition: inline
  283. Content-Type: text/plain
  284. Delete
  285. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04
  286. Content-Transfer-Encoding: quoted-printable
  287. Content-Disposition: inline
  288. Content-Type: text/html
  289. <p>Delete</p>
  290. --7352524eaae801790245f6bf095460fd1f4e01f5748b4dba48635bf59b04--
  291. --bdfa9bf94e22e218105281e06bd59bd6df3ce70e71367bf49fbe73301af3--`
  292. s := Session{
  293. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  294. Ctx: &context.Context{},
  295. }
  296. s.Data(bytes.NewReader([]byte(deleteEmail)))
  297. }
  298. func TestNullCC(t *testing.T) {
  299. testInit()
  300. emailData := `Date: Mon, 29 Jan 2024 16:54:30 +0800
  301. Return-Path: 1231@111.com
  302. From: =?utf-8?B?b2VhdHY=?= 1231@111.com
  303. To: =?utf-8?B?ODQ2ODAzOTY=?= 123213@qq.com
  304. Cc:
  305. Bcc:
  306. Reply-To: <>
  307. Subject: =?utf-8?B?6L+Z5piv5LiA5bCB5p2l6IeqUmVsYXhEcmFtYeeahOmCruS7tg==?=
  308. Message-ID: <cf43cc780b72dad392d4f90dfced88a8@1231@111.com>
  309. X-Priority: 3
  310. X-Mailer: Mailer (https://github.com/txthinking/Mailer)
  311. MIME-Version: 1.0
  312. Content-Type: multipart/alternative; boundary="6edc2ef285d93010a080caccc858c67b"
  313. --6edc2ef285d93010a080caccc858c67b
  314. Content-Type: text/plain; charset="UTF-8"
  315. Content-Transfer-Encoding: base64
  316. PGRpdiBzdHlsZT0ibWluLWhlaWdodDo1NTBweDsgcGFkZGluZzogMTAwcHggNTVweCAyMDBweDsi
  317. Pui/meaYr+S4gOWwgeadpeiHqlJlbGF4RHJhbWHnmoTmoKHpqozpgq7ku7Ys55So5LqO5qCh6aqM
  318. 6YKu5Lu26YWN572u5piv5ZCm5q2j5bi4ITwvZGl2Pg==
  319. --6edc2ef285d93010a080caccc858c67b
  320. Content-Type: text/html; charset="UTF-8"
  321. Content-Transfer-Encoding: base64
  322. PGRpdiBzdHlsZT0ibWluLWhlaWdodDo1NTBweDsgcGFkZGluZzogMTAwcHggNTVweCAyMDBweDsi
  323. Pui/meaYr+S4gOWwgeadpeiHqlJlbGF4RHJhbWHnmoTmoKHpqozpgq7ku7Ys55So5LqO5qCh6aqM
  324. 6YKu5Lu26YWN572u5piv5ZCm5q2j5bi4ITwvZGl2Pg==
  325. --6edc2ef285d93010a080caccc858c67b--`
  326. s := Session{
  327. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  328. Ctx: &context.Context{},
  329. }
  330. s.Data(bytes.NewReader([]byte(emailData)))
  331. }
  332. func TestRuleMove(t *testing.T) {
  333. testInit()
  334. moveEmail := `DKIM-Signature: a=rsa-sha256; bh=YQfG/wlHGhky6FNmpIwgDYDOc/uyivdBv+9S02Z04xY=;
  335. c=simple/simple; d=jinnrry.com;
  336. h=Content-Type:Mime-Version:Subject:To:From:Date; s=default; t=1693992542;
  337. v=1;
  338. b=IhxswOCq8I7CmCas1EMp+n8loR7illqlF0IJC6eN1+OLjI/E5BPzpP4HWkyqaAkd0Vn9i+Bn
  339. MVb5kNHZ2S7qt0rqAAc6Atc0i9WpLEI3Cng+VDn+difcMZlJSAkhLLn2sUsS4Fzqqo3Cbw62qSO
  340. TgnWRmlj9aM+5xfGcl/76WOvQQpahJbGg6Go51kFMeHVom/VeGKIgFBCeMe37T/LS03c3pAV8gA
  341. i6Zy3GYE57W/qU3oCzaGeS3n5zom/i74H4VipiVIMX/OBNYhdHWrP8vyjvzLFpJlXp6RvzcRl0P
  342. ytyiCZfE8G7fAFntp20LW70Y5Xgqqczk1jR578UDczVoA==
  343. Content-Type: multipart/mixed;
  344. boundary=c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d
  345. Mime-Version: 1.0
  346. Subject: Move
  347. To: <t@jiangwei.one>
  348. From: "i" <i@jinnrry.com>
  349. Date: Wed, 06 Sep 2023 17:29:02 +0800
  350. --c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d
  351. Content-Type: multipart/alternative;
  352. boundary=a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  353. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  354. Content-Transfer-Encoding: quoted-printable
  355. Content-Disposition: inline
  356. Content-Type: text/plain
  357. MOVE move Move
  358. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966
  359. Content-Transfer-Encoding: quoted-printable
  360. Content-Disposition: inline
  361. Content-Type: text/html
  362. <p>MOVE move Move</p>
  363. --a69985ebcf3c1c44d6e69e5a29c1044743cd9e44d4bc9bb6886f83a73966--
  364. --c84d60b253aa6caee345c73e717ad59b1975448bbdfad7a23ac4d76e022d--`
  365. s := Session{
  366. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  367. Ctx: &context.Context{},
  368. }
  369. s.Data(bytes.NewReader([]byte(moveEmail)))
  370. }
  371. func TestQAEmailForward(t *testing.T) {
  372. testInit()
  373. data := `Mime-Version: 1.0
  374. X-QQ-MIME: TCMime 1.0 by Tencent
  375. X-Mailer: QQMail 2.x
  376. X-QQ-Mailer: QQMail 2.x
  377. Message-ID: tencent_D82739970C66D2BFBA23F4A3@qq.com
  378. Subject: =?UTF-8?B?5rWL6K+V5Y+R6YCB?=
  379. Date: Wed, 10 Apr 2024 11:11:12 +0800 (GMT+08:00)
  380. From: =?UTF-8?B?YWRtaW5AamlubnJyeS5jb20=?=<admin@jinnrry.com>
  381. To: =?UTF-8?B??=<test@jinnrry.com>
  382. Content-Type: multipart/alternative;
  383. boundary="----=_Part_174_107154538.1712718674768"
  384. ------=_Part_174_107154538.1712718674768
  385. Content-Type: text/plain; charset=us-ascii
  386. Content-Transfer-Encoding: base64
  387. ------=_Part_174_107154538.1712718674768
  388. Content-Type: text/html; charset=UTF-8
  389. Content-Transfer-Encoding: base64
  390. PGRpdj7ov5nph4zmmK/lhoXlrrk8L2Rpdj48ZGl2PjwhLS1lbXB0eXNpZ24tLT48L2Rpdj4=
  391. ------=_Part_174_107154538.1712718674768--`
  392. s := Session{
  393. RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
  394. Ctx: &context.Context{},
  395. }
  396. s.Data(bytes.NewReader([]byte(data)))
  397. }