read_content_test.go 16 KB

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