read_content_test.go 16 KB

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