uo_email.sru 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. $PBExportHeader$uo_email.sru
  2. forward
  3. global type uo_email from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_email from nonvisualobject
  7. event ue_revemail ( )
  8. end type
  9. global uo_email uo_email
  10. type variables
  11. //string fjfilepathname = 'fjtemp'
  12. //s_email_set s_set[],cur_set
  13. //long sumcnt
  14. //long finishcnt
  15. Transaction commit_tran
  16. Transaction fj_tran
  17. string C_Sys_admsg_fj = 'Sys_admsg_fj'
  18. string C_u_email_fj = 'u_email_fj'
  19. string C_from_file = 'from_file'
  20. end variables
  21. forward prototypes
  22. public function integer f_update_send (long arg_sendid, datetime arg_senddate, long arg_mailsize, ref string arg_msg)
  23. public function integer f_check_rep (ref s_email_sendmx arg_sendmx, ref string arg_msg)
  24. public function integer f_send (s_email_set arg_set, s_email_send arg_send, s_email_sendmx arg_sendmx, s_email_fj arg_fj, ref string arg_msg)
  25. public function integer uf_get_send (long arg_sendid, ref s_email_send arg_s_send, ref string arg_msg)
  26. public subroutine wf_str_replace (ref string arg_source, string arg_str1, string arg_str2)
  27. public function integer wf_mail_gethtml (long arg_msgid, ref string arg_text, ref string arg_msg)
  28. public function integer uf_get_sendmx (long arg_sendid, ref s_email_sendmx arg_sendmx[], ref string arg_msg)
  29. public function integer wf_mail_getfjblob (long arg_fjid, ref blob arg_fjblob, ref string arg_msg)
  30. public function integer uf_get_fj (long arg_relid, ref s_email_lvfj arg_lvfj[], ref string arg_msg, boolean arg_withblob)
  31. public function integer wf_admsg_getfjblob (long arg_fjid, ref blob arg_fjblob, ref string arg_msg)
  32. public function integer f_del (long arg_id, ref string arg_msg)
  33. public function integer wf_ds_get_mail_set (long arg_mailid, ref s_email_set arg_set, ref string arg_msg)
  34. public function long wf_ds_gettrunkbox (long arg_mailid)
  35. public function long wf_ds_getsendbox (long arg_mailid)
  36. public function string wf_ds_getuser (long arg_id)
  37. public function string wf_ds_getaddress (long arg_id)
  38. public function string wf_ds_getuseraddress (long arg_id)
  39. public function integer wf_ds_move_msg_box (long arg_id, long arg_boxid, ref string arg_msg)
  40. public function integer f_del_move_msg (long arg_id, ref string arg_msg)
  41. public function integer f_unread (long arg_revid, ref string arg_msg)
  42. public function integer f_read (long arg_revid, ref string arg_msg)
  43. public function long f_save (ref s_email_send arg_send, s_email_sendmx arg_sendmx[], s_email_lvfj arg_fj[], ref string arg_msg)
  44. public function long f_import_eml (ref s_email_send arg_send, s_email_lvfj arg_fj[], ref string arg_msg)
  45. public function integer f_change_id (long arg_fromid, long arg_toid, ref string arg_msg)
  46. end prototypes
  47. event ue_revemail();//Long i
  48. //string ls_msg
  49. //FOR i = 1 TO sumcnt
  50. // IF pf_revemail(s_set[i],ls_msg) = 0 THEN
  51. //
  52. // END IF
  53. //NEXT
  54. //
  55. end event
  56. public function integer f_update_send (long arg_sendid, datetime arg_senddate, long arg_mailsize, ref string arg_msg);Long rslt = 1
  57. //UPDATE u_email_send
  58. // SET senddate = :arg_senddate,
  59. // mailsize = :arg_mailsize,
  60. // mailtype = 1
  61. // Where u_email_send.sendid = :arg_sendid
  62. // and not exists (select 0 from u_email_sendmx where sendid = u_email_send.sendID and status = 0)
  63. // using commit_tran;
  64. //IF commit_tran.SQLCode <> 0 THEN
  65. // rslt = 0
  66. // arg_msg = '更新邮件信息失败'
  67. //END IF
  68. RETURN rslt
  69. end function
  70. public function integer f_check_rep (ref s_email_sendmx arg_sendmx, ref string arg_msg);Long cnt,rslt = 1,ll_id
  71. cnt = 0
  72. SELECT count(*)
  73. INTO :cnt
  74. FROM u_email_rep
  75. WHERE empid = :sys_empid AND
  76. LTRIM(RTRIM(Lower(mailAddress))) = LTRIM(RTRIM(Lower(:arg_sendmx.revaddress))) Using commit_tran;
  77. IF commit_tran.SQLCode <> 0 THEN
  78. rslt = 0
  79. arG_MSG = "查询联系人列表失败~n"+commit_tran.SQLErrText
  80. GOTO ext
  81. END IF
  82. IF cnt = 0 THEN
  83. ll_id = f_sys_scidentity(0,"u_email_rep","repID",arG_MSG,True, commit_tran) //数据commit事务)
  84. IF ll_id <= 0 THEN
  85. rslt = 0
  86. GOTO ext
  87. END IF
  88. INSERT INTO u_email_rep
  89. ( repID,
  90. empid,
  91. mailname,
  92. mailaddress,
  93. Opemp,
  94. Opdate,
  95. reptype )
  96. VALUES ( :ll_id,
  97. :sys_empid,
  98. :arg_sendmx.revname ,
  99. LTRIM(RTRIM(LOWER(:arg_sendmx.revaddress))),
  100. :publ_operator,
  101. getdate(),
  102. 1 ) Using commit_tran ;
  103. IF commit_tran.SQLCode <> 0 THEN
  104. rslt = 0
  105. arG_MSG = "插入联系人列表失败~n"+commit_tran.SQLErrText
  106. GOTO ext
  107. END IF
  108. arg_sendmx.reltype = 0
  109. arg_sendmx.relid = ll_id
  110. ELSE
  111. IF arg_sendmx.reltype = 0 Or arg_sendmx.reltype = 3 THEN//类型为通讯录和手动的查询联系人表
  112. SELECT top 1 repID,
  113. mailname
  114. INTO :arg_sendmx.relid,
  115. :arg_sendmx.revname
  116. FROM u_email_rep
  117. WHERE empid = :sys_empid AND
  118. LTRIM(RTRIM(Lower(mailAddress))) = LTRIM(RTRIM(Lower(:arg_sendmx.revaddress))) Using commit_tran;
  119. arg_sendmx.reltype = 0
  120. END IF
  121. END IF
  122. ext:
  123. RETURN rslt
  124. end function
  125. public function integer f_send (s_email_set arg_set, s_email_send arg_send, s_email_sendmx arg_sendmx, s_email_fj arg_fj, ref string arg_msg);Long rslt = 1,k,l
  126. //Blob lb_fj
  127. //String ls_pathname[]
  128. //Long ll_fjid ,it_max
  129. //arg_msg = ''
  130. //it_max = 0
  131. //oleobject jmail
  132. //jmail = CREATE oleobject
  133. //jmail.ConnectToNewObject("JMail.Message")
  134. //jmail.Charset = 'GB2312'
  135. //jmail.ISOEncodeHeaders = TRUE
  136. //jmail.silent = TRUE
  137. //jmail.Logging = TRUE
  138. //
  139. //jmail.FROM = arg_set.mailAddress //发件人邮箱
  140. //jmail.FromName = arg_set.mailuser //发件人
  141. //jmail.Subject = Trim(arg_send.Subject) //邮件主题
  142. //jmail.MailServerUserName = arg_set.mailAddress //发件邮箱登录账户
  143. //jmail.MailServerPassword = arg_set.mailpsw //发件邮箱用户密码
  144. //jmail.Priority = arg_send.Priority //优先级
  145. ////jmail.Body = Trim(arg_send.Textbody) + "~r~n" //邮件内容
  146. //jmail.htmlbody = string(arg_send.htmlbody)
  147. //FOR l = 1 TO UpperBound(arg_fj.fjid)
  148. // if arg_fj.fjid[l] = 0 then continue
  149. // ll_fjid = arg_fj.fjid[l]
  150. // SELECTBLOB Fileblob
  151. // INTO :lb_fj
  152. // FROM u_email_fj
  153. // Where (fjid = :ll_fjid) using fj_tran;
  154. //
  155. // IF fj_tran.SQLCode <> 0 THEN
  156. // arg_msg = '下载附件失败'
  157. //
  158. // rslt = 0
  159. // GOTO ext
  160. // END IF
  161. //
  162. // it_max ++
  163. // ls_pathname[it_max] = sys_cur_path+fjfilepathname+'\'+arg_fj.Filename[l]
  164. // IF FileExists(ls_pathname[it_max]) THEN FileDelete(ls_pathname[it_max])
  165. // IF f_blobtofile(ls_pathname[it_max],lb_fj,arg_msg) = 0 THEN
  166. //
  167. // rslt = 0
  168. // GOTO ext
  169. // ELSE
  170. // jmail.AddAttachment(ls_pathname[it_max])
  171. // END IF
  172. //NEXT
  173. //
  174. //////添加联系人
  175. //long ll_sent_num = 0
  176. //if arg_send.normal_flag = 2 then
  177. // FOR k = 1 TO UpperBound(arg_sendmx.revaddress)
  178. // IF Trim(arg_sendmx.revaddress[k]) <> '' THEN
  179. // jmail.AddRecipient(Trim(arg_sendmx.revaddress[k]))
  180. // if not jmail.send(arg_set.smtpset) then
  181. // rslt = 0
  182. // arg_msg = arg_msg + "发送[" + Trim(arg_sendmx.revaddress[k]) + "]失败![" + arg_set.mailAddress + "]邮箱设置不正确或者没有连接网络~r~n"
  183. // else
  184. // // DONE : 修改收件人列表状态
  185. // ll_sent_num ++
  186. // update u_email_sendmx
  187. // set u_email_sendmx.status = 1
  188. // where u_email_sendmx.sendid = :arg_send.sendid and u_email_sendmx.printid = :arg_sendmx.printid[k] using commit_tran;
  189. // if commit_tran.sqlcode <> 0 then
  190. // rslt = 0
  191. // arg_msg = arg_msg + "更新收件人[" + Trim(arg_sendmx.revaddress[k]) + "]状态失败~r~n"
  192. // else
  193. // commit;
  194. // end if
  195. //
  196. // end if
  197. // jmail.ClearRecipients()
  198. // END IF
  199. // NEXT
  200. //else
  201. // jmail.ClearRecipients()
  202. // for k = 1 to upperBound(arg_sendmx.revaddress)
  203. // IF Trim(arg_sendmx.revaddress[k]) <> '' THEN
  204. //// Messagebox('', arg_sendmx.revaddress[k])
  205. // if arg_send.normal_flag = 0 then
  206. // jmail.AddRecipient(Trim(arg_sendmx.revaddress[k]))
  207. // elseif arg_send.normal_flag = 1 then
  208. // jmail.AddRecipientBCC(Trim(arg_sendmx.revaddress[k]))
  209. // end if
  210. // end if
  211. // next
  212. //
  213. // //// debug///////
  214. //// oleobject stream
  215. //// stream = CREATE oleobject
  216. //// stream.ConnectToNewObject("Adodb.Stream")
  217. //// stream.Type = 1
  218. //// stream.open()
  219. //// jmail.SaveToStream(stream)
  220. //// stream.position = 0
  221. //// blob lb_message
  222. //// setnull(lb_message)
  223. //// lb_message = stream.read(stream.size)
  224. //// stream.close()
  225. //// stream.disconnectobject( )
  226. //// destroy stream
  227. //// messagebox('', string(lb_message))
  228. // //// debug///////
  229. //
  230. // if not jmail.send(arg_set.smtpset) then
  231. // rslt = 0
  232. // arg_msg = arg_msg + "发送失败![" + arg_set.mailAddress + "]邮箱设置不正确或者没有连接网络~r~n"
  233. // else
  234. // // DONE : 修改收件人列表状态
  235. // for k = 1 to upperBound(arg_sendmx.revaddress)
  236. // ll_sent_num ++
  237. // update u_email_sendmx
  238. // set u_email_sendmx.status = 1
  239. // where u_email_sendmx.sendid = :arg_send.sendid and u_email_sendmx.printid = :arg_sendmx.printid[k] using commit_tran;
  240. // if commit_tran.sqlcode <> 0 then
  241. // rslt = 0
  242. // arg_msg = arg_msg + "更新收件人[" + Trim(arg_sendmx.revaddress[k]) + "]状态失败~r~n"
  243. // else
  244. // commit;
  245. // end if
  246. // next
  247. // end if
  248. // jmail.ClearRecipients()
  249. //end if
  250. //
  251. //// DONE: 删除临时文件
  252. //for l = 1 to it_max
  253. // IF FileExists(ls_pathname[l]) THEN FileDelete(ls_pathname[l])
  254. //next
  255. //// DONE: 更改邮件状态
  256. //if ll_sent_num > 0 then
  257. // if f_update_send(arg_send.sendid, jmail.date, jmail.size, arg_msg) = 0 then
  258. // rslt = 0
  259. // arg_msg = arg_msg + "更改邮件状态失败~r~n"
  260. // goto ext
  261. // end if
  262. //else
  263. // rslt = 0
  264. // arg_msg = arg_msg + "没有更改邮件发送状态"
  265. // GOTO ext
  266. //end if
  267. //
  268. //
  269. ////IF jmail.Send(arg_set.smtpset) THEN //ls_host为发件邮箱服务器
  270. ////
  271. //// jmail.ClearAttachments()
  272. //// jmail.ClearRecipients()
  273. ////
  274. //// IF f_update_send(arg_send.sendid,jmail.Date,jmail.size,arg_msg) = 0 THEN
  275. //// rslt = 0
  276. //// GOTO ext
  277. //// END IF
  278. ////
  279. //// for l = 1 to it_max
  280. //// IF FileExists(ls_pathname[l]) THEN FileDelete(ls_pathname[l])
  281. //// next
  282. ////
  283. ////ELSE
  284. //// arg_msg = "发送失败![" + arg_set.mailAddress + "]邮箱设置不正确或者没有连接网络"
  285. //// rslt = 0
  286. //// GOTO ext
  287. ////END IF
  288. //
  289. //ext:
  290. //jmail.Close()
  291. //DESTROY jmail
  292. RETURN rslt
  293. end function
  294. public function integer uf_get_send (long arg_sendid, ref s_email_send arg_s_send, ref string arg_msg);integer rslt = 1
  295. string ls_html
  296. SELECT u_email_msg.ID,
  297. u_email_msg.boxid,
  298. u_email_msg.mailID,
  299. u_email_msg.mailaddress,
  300. u_email_msg.mailtype,
  301. u_email_msg.Subject,
  302. u_email_msg.Priority,
  303. u_email_msg.senddate,
  304. u_email_msg.Opdate,
  305. u_email_msg.opemp,
  306. u_email_msg.mailsize,
  307. u_email_msg.sendOption,
  308. u_email_msg.senduser,
  309. u_email_msg.sendaddress,
  310. u_email_msg.revdate
  311. INTO :arg_s_send.sendid,
  312. :arg_s_send.boxid,
  313. :arg_s_send.mailid,
  314. :arg_s_send.mailaddress,
  315. :arg_s_send.mailtype,
  316. :arg_s_send.Subject,
  317. :arg_s_send.Priority,
  318. :arg_s_send.senddate,
  319. :arg_s_send.opdate,
  320. :arg_s_send.opemp,
  321. :arg_s_send.mailsize,
  322. :arg_s_send.normal_flag,
  323. :arg_s_send.senduser,
  324. :arg_s_send.sendaddress,
  325. :arg_s_send.revdate
  326. FROM u_email_msg
  327. where u_email_msg.ID = :arg_sendID using fj_tran;
  328. if fj_tran.sqlcode <> 0 then
  329. rslt = 0
  330. arg_msg = "获取邮件失败,id:" + string(arg_sendid)
  331. goto ext
  332. end if
  333. if wf_mail_gethtml(arg_sendid, arg_s_send.htmlbody, arg_msg) <> 1 then
  334. rslt = 0
  335. goto ext
  336. end if
  337. // DONE: revlist
  338. ext:
  339. return rslt
  340. end function
  341. public subroutine wf_str_replace (ref string arg_source, string arg_str1, string arg_str2);long ll_pos
  342. ll_pos = pos(arg_source, arg_str1, 1)
  343. do while ll_pos > 0
  344. arg_source = Replace(arg_source, ll_pos, len(arg_str1), arg_str2)
  345. ll_pos = pos(arg_source, arg_str1,1)
  346. LOOP
  347. end subroutine
  348. public function integer wf_mail_gethtml (long arg_msgid, ref string arg_text, ref string arg_msg);int rslt = 1
  349. long len
  350. BLOB lb
  351. SELECT DATALENGTH(htmlbody) INTO :len FROM u_email_msg
  352. WHERE ID = :arg_msgid using fj_tran;
  353. if fj_tran.sqlcode <> 0 then
  354. rslt = 0
  355. arg_msg = '查询html长度失败,' + fj_tran.sqlerrtext
  356. goto ext
  357. end if
  358. if len = 0 then
  359. SELECT DATALENGTH(textbody) INTO :len FROM u_email_msg
  360. WHERE ID = :arg_msgid using fj_tran;
  361. if fj_tran.sqlcode <> 0 then
  362. rslt = 0
  363. arg_msg = '查询text长度失败,' + fj_tran.sqlerrtext
  364. goto ext
  365. end if
  366. if len > 2048 then
  367. SELECTBLOB textbody INTO :lb FROM u_email_msg
  368. WHERE ID = :arg_msgid using fj_tran;
  369. if fj_tran.sqlcode <> 0 then
  370. rslt = 0
  371. arg_msg = '查询text失败,' + fj_tran.sqlerrtext
  372. goto ext
  373. end if
  374. arg_text = string(lb)
  375. wf_str_replace(arg_text, '~r~n', '<BR>')
  376. wf_str_replace(arg_text, '~r', '<BR>')
  377. wf_str_replace(arg_text, '~n', '<BR>')
  378. else
  379. SELECT textbody INTO :arg_text FROM u_email_msg
  380. WHERE ID = :arg_msgid using fj_tran;
  381. if fj_tran.sqlcode <> 0 then
  382. rslt = 0
  383. arg_msg = '查询text失败,' + fj_tran.sqlerrtext
  384. goto ext
  385. end if
  386. wf_str_replace(arg_text, '~r~n', '<BR>')
  387. wf_str_replace(arg_text, '~r', '<BR>')
  388. wf_str_replace(arg_text, '~n', '<BR>')
  389. end if
  390. elseif len > 2048 then
  391. SELECTBLOB htmlbody INTO :lb FROM u_email_msg
  392. WHERE ID = :arg_msgid using fj_tran;
  393. if fj_tran.sqlcode <> 0 then
  394. rslt = 0
  395. arg_msg = '查询html失败,' + fj_tran.sqlerrtext
  396. goto ext
  397. end if
  398. arg_text = string(lb)
  399. else
  400. SELECT htmlbody INTO :arg_text FROM u_email_msg
  401. WHERE ID = :arg_msgid using fj_tran;
  402. if fj_tran.sqlcode <> 0 then
  403. rslt = 0
  404. arg_msg = '查询html失败,' + fj_tran.sqlerrtext
  405. goto ext
  406. end if
  407. end if
  408. ext:
  409. return rslt
  410. end function
  411. public function integer uf_get_sendmx (long arg_sendid, ref s_email_sendmx arg_sendmx[], ref string arg_msg);Int rslt = 1,i,NO_MXCHECK
  412. i = 0
  413. s_email_sendmx s_sendmx[]
  414. long sendid, printid, reltype, relid
  415. string revaddress, revname
  416. DECLARE CUR_INWAERMX CURSOR FOR
  417. SELECT u_email_sendmx.sendid,
  418. u_email_sendmx.printid,
  419. u_email_sendmx.reltype,
  420. u_email_sendmx.relid,
  421. u_email_sendmx.revaddress,
  422. u_email_sendmx.revname
  423. FROM u_email_sendmx
  424. where u_email_sendmx.sendid = :arg_sendid using fj_tran;
  425. OPEN CUR_INWAERMX;
  426. FETCH CUR_INWAERMX INTO :sendid,
  427. :printid,
  428. :reltype,
  429. :relid,
  430. :revaddress,
  431. :revname;
  432. DO WHILE fj_tran.SQLCode = 0
  433. i++
  434. s_sendmx[i].sendid = sendid
  435. s_sendmx[i].printid = printid
  436. s_sendmx[i].reltype = reltype
  437. s_sendmx[i].relid = relid
  438. s_sendmx[i].revaddress = revaddress
  439. s_sendmx[i].revname = revname
  440. FETCH CUR_INWAERMX INTO :sendid,
  441. :printid,
  442. :reltype,
  443. :relid,
  444. :revaddress,
  445. :revname;
  446. LOOP
  447. CLOSE CUR_INWAERMX;
  448. arg_sendmx = s_sendmx
  449. RETURN rslt
  450. end function
  451. public function integer wf_mail_getfjblob (long arg_fjid, ref blob arg_fjblob, ref string arg_msg);int rslt = 1
  452. SELECTBLOB fileblob INTO :arg_fjblob FROM u_email_fj
  453. WHERE fjid = :arg_fjid using fj_tran;
  454. if fj_tran.sqlcode <> 0 then
  455. rslt = 0
  456. arg_msg = '获取附件失败,' + fj_tran.sqlerrtext
  457. goto ext
  458. end if
  459. ext:
  460. return rslt
  461. end function
  462. public function integer uf_get_fj (long arg_relid, ref s_email_lvfj arg_lvfj[], ref string arg_msg, boolean arg_withblob);Int rslt = 1,i
  463. i = 0
  464. long fjid, fjtype, relid
  465. string filename, filetype,cid
  466. s_email_lvfj l_s_lvfj[]
  467. DECLARE CUR_INWAERMX CURSOR FOR
  468. SELECT u_email_fj.fjid,
  469. u_email_fj.fjtype,
  470. u_email_fj.Relid,
  471. u_email_fj.filename,
  472. u_email_fj.filetype ,
  473. u_email_fj.cid
  474. FROM u_email_fj
  475. where u_email_fj.Relid = :arg_Relid using fj_tran;
  476. OPEN CUR_INWAERMX;
  477. FETCH CUR_INWAERMX INTO :fjid,
  478. :fjtype,
  479. :Relid,
  480. :filename,
  481. :filetype,
  482. :cid;
  483. DO WHILE fj_tran.SQLCode = 0
  484. i++
  485. l_s_lvfj[i].fjid = fjid
  486. l_s_lvfj[i].fjtype = fjtype
  487. l_s_lvfj[i].Relid = Relid
  488. l_s_lvfj[i].filename = filename
  489. l_s_lvfj[i].filetype = C_u_email_fj
  490. l_s_lvfj[i].cid = cid
  491. FETCH CUR_INWAERMX INTO :fjid,
  492. :fjtype,
  493. :Relid,
  494. :filename,
  495. :filetype,
  496. :cid;
  497. LOOP
  498. CLOSE CUR_INWAERMX;
  499. if arg_withBlob then
  500. for i = 1 to UPPERBOUND(l_s_lvfj)
  501. if wf_mail_getfjblob(l_s_lvfj[i].fjid, l_s_lvfj[i].fileblob, arg_msg) <> 1 then
  502. rslt = 0
  503. goto ext
  504. end if
  505. next
  506. end if
  507. arg_lvfj = l_s_lvfj
  508. ext:
  509. RETURN rslt
  510. end function
  511. public function integer wf_admsg_getfjblob (long arg_fjid, ref blob arg_fjblob, ref string arg_msg);int rslt = 1
  512. SELECTBLOB fileblob INTO :arg_fjblob FROM Sys_admsg_fj
  513. WHERE fjid = :arg_fjid using Commit_Tran;
  514. if Commit_Tran.sqlcode <> 0 then
  515. rslt = 0
  516. arg_msg = '获取内部消息附件失败,' + Commit_Tran.sqlerrtext
  517. goto ext
  518. end if
  519. ext:
  520. return rslt
  521. end function
  522. public function integer f_del (long arg_id, ref string arg_msg);Int rslt = 1
  523. // fjtype : 0:发件箱 1:收件箱
  524. // mailtype : 0:未发,未读1:已发,已读2:废件箱
  525. DELETE FROM u_email_msg WHERE ID = :arg_id using fj_tran;
  526. if fj_tran.sqlcode <> 0 then
  527. rslt = 0
  528. arg_msg = '删除邮件失败,' + fj_tran.sqlerrtext
  529. goto ext
  530. end if
  531. DELETE FROM u_email_sendmx WHERE sendid = :arg_id using fj_tran;
  532. if fj_tran.sqlcode <> 0 then
  533. rslt = 0
  534. arg_msg = '删除收件人列表失败,' + fj_tran.sqlerrtext
  535. goto ext
  536. end if
  537. DELETE FROM u_email_fj WHERE relid = :arg_id using fj_tran;
  538. if fj_tran.sqlcode <> 0 then
  539. rslt = 0
  540. arg_msg = '删除附件失败,' + fj_tran.sqlerrtext
  541. goto ext
  542. end if
  543. ext:
  544. IF rslt = 0 THEN
  545. ROLLBACK USING fj_tran;
  546. ELSE
  547. COMMIT USING fj_tran;
  548. END IF
  549. RETURN rslt
  550. end function
  551. public function integer wf_ds_get_mail_set (long arg_mailid, ref s_email_set arg_set, ref string arg_msg);int rslt = 1
  552. SELECT mailuser, mailaddress
  553. INTO :arg_set.mailuser, :arg_set.mailaddress
  554. FROM u_email_set
  555. WHERE mailID = :arg_mailid using Commit_Tran;
  556. if Commit_Tran.sqlcode <> 0 then
  557. rslt = 0
  558. arg_msg = '查询帐号信息失败,' + Commit_Tran.sqlerrtext
  559. goto ext
  560. end if
  561. arg_set.mailid = arg_mailid
  562. ext:
  563. return rslt
  564. end function
  565. public function long wf_ds_gettrunkbox (long arg_mailid);long rslt = -1
  566. SELECT TOP 1 boxid INTO :rslt
  567. FROM u_email_box
  568. WHERE mailid = :arg_mailid AND boxtype = '废件箱' using Commit_Tran;
  569. if Commit_Tran.sqlcode <> 0 then
  570. return -1
  571. end if
  572. return rslt
  573. end function
  574. public function long wf_ds_getsendbox (long arg_mailid);long rslt = -1
  575. SELECT TOP 1 boxid INTO :rslt
  576. FROM u_email_box
  577. WHERE mailid = :arg_mailid AND boxtype = '发件箱' using Commit_Tran;
  578. if Commit_Tran.sqlcode <> 0 then
  579. return -1
  580. end if
  581. return rslt
  582. end function
  583. public function string wf_ds_getuser (long arg_id);string rslt = ''
  584. long ll_cnt
  585. SELECT COUNT(0) INTO :ll_cnt FROM u_email_sendmx
  586. WHERE sendid = :arg_id using fj_tran;
  587. if fj_tran.sqlcode <> 0 then
  588. return rslt
  589. end if
  590. if ll_cnt = 0 then
  591. return rslt
  592. end if
  593. string revname
  594. declare cur1 CURSOR FOR
  595. SELECT revname FROM u_email_sendmx
  596. WHERE sendid = :arg_id ORDER BY printid using fj_tran;
  597. open cur1;
  598. fetch cur1 INTO :revname;
  599. do while fj_tran.sqlcode = 0
  600. rslt = rslt + revname + ';'
  601. fetch cur1 INTO :revname;
  602. LOOP
  603. close cur1;
  604. rslt = left(rslt, len(rslt) - 1)
  605. return rslt
  606. end function
  607. public function string wf_ds_getaddress (long arg_id);string rslt = ''
  608. long ll_cnt
  609. SELECT COUNT(0) INTO :ll_cnt FROM u_email_sendmx
  610. WHERE sendid = :arg_id using fj_tran;
  611. if fj_tran.sqlcode <> 0 then
  612. return rslt
  613. end if
  614. if ll_cnt = 0 then
  615. return rslt
  616. end if
  617. string revname
  618. declare cur1 CURSOR FOR
  619. SELECT revaddress FROM u_email_sendmx
  620. WHERE sendid = :arg_id ORDER BY printid using fj_tran;
  621. open cur1;
  622. fetch cur1 INTO :revname;
  623. do while fj_tran.sqlcode = 0
  624. rslt = rslt + revname + ';'
  625. fetch cur1 INTO :revname;
  626. LOOP
  627. close cur1;
  628. rslt = left(rslt, len(rslt) - 1)
  629. return rslt
  630. end function
  631. public function string wf_ds_getuseraddress (long arg_id);string rslt = ''
  632. long ll_cnt
  633. SELECT COUNT(0) INTO :ll_cnt FROM u_email_sendmx
  634. WHERE sendid = :arg_id using fj_tran;
  635. if fj_tran.sqlcode <> 0 then
  636. return rslt
  637. end if
  638. if ll_cnt = 0 then
  639. return rslt
  640. end if
  641. string revname
  642. declare cur1 CURSOR FOR
  643. SELECT revname + '<' + revaddress + '>' as address FROM u_email_sendmx
  644. WHERE sendid = :arg_id ORDER BY printid using fj_tran;
  645. open cur1;
  646. fetch cur1 INTO :revname;
  647. do while fj_tran.sqlcode = 0
  648. rslt = rslt + revname + ';'
  649. fetch cur1 INTO :revname;
  650. LOOP
  651. close cur1;
  652. rslt = left(rslt, len(rslt) - 1)
  653. return rslt
  654. end function
  655. public function integer wf_ds_move_msg_box (long arg_id, long arg_boxid, ref string arg_msg);int rslt = 1
  656. long mailid
  657. SELECT mailid INTO :mailid
  658. FROM u_email_box WHERE boxid = :arg_boxid using Commit_Tran;
  659. if Commit_Tran.sqlcode <> 0 then
  660. rslt = 0
  661. arg_msg = '查询邮箱所属帐号失败,' + Commit_Tran.sqlerrtext
  662. goto ext
  663. end if
  664. UPDATE u_email_msg SET boxid = :arg_boxid, mailid = :mailid
  665. WHERE ID = :arg_id using fj_tran;
  666. if fj_tran.sqlcode <> 0 then
  667. rslt = 0
  668. arg_msg = '移动邮件失败,' + fj_tran.sqlerrtext
  669. goto ext
  670. end if
  671. if fj_tran.SQLNRows <> 1 then
  672. rslt = 0
  673. arg_msg = '原邮件已经不存在'
  674. goto ext
  675. end if
  676. ext:
  677. if rslt = 0 then
  678. rollback using fj_tran;
  679. else
  680. commit using fj_tran;
  681. end if
  682. return rslt
  683. end function
  684. public function integer f_del_move_msg (long arg_id, ref string arg_msg);int rslt = 1
  685. long mailid, boxid
  686. SELECT mailid, boxid INTO :mailid, :boxid
  687. FROM u_email_msg WHERE ID = :arg_id using fj_tran;
  688. if fj_tran.sqlcode <> 0 then
  689. rslt = 0
  690. arg_msg = '查询邮件失败,邮件可能不存在,' + fj_tran.sqlerrtext
  691. goto ext
  692. end if
  693. long trunkboxid
  694. trunkboxid = wf_ds_gettrunkbox(mailid)
  695. if trunkboxid <= 0 then
  696. rslt = 0
  697. arg_msg = '获取默认废件箱失败'
  698. goto ext
  699. end if
  700. if boxid = trunkboxid then
  701. if f_del(arg_id, arg_msg) <> 1 then
  702. rslt = 0
  703. goto ext
  704. end if
  705. else
  706. if wf_ds_move_msg_box(arg_id, trunkboxid, arg_msg) <> 1 then
  707. rslt = 0
  708. goto ext
  709. end if
  710. end if
  711. ext:
  712. if rslt = 0 then
  713. rollback using fj_tran;
  714. else
  715. commit using fj_tran;
  716. end if
  717. return rslt
  718. end function
  719. public function integer f_unread (long arg_revid, ref string arg_msg);Long rslt = 1
  720. UPDATE u_email_msg
  721. SET status = '未读'
  722. Where u_email_msg.ID = :arg_revid using fj_tran;
  723. IF fj_tran.SQLCode <> 0 THEN
  724. rslt = 0
  725. arG_MSG = "更新收件标记失败~n"+fj_tran.SQLErrText
  726. GOTO ext
  727. END IF
  728. ext:
  729. IF rslt = 0 THEN
  730. ROLLBACK using fj_tran;
  731. ELSE
  732. COMMIT using fj_tran;
  733. END IF
  734. RETURN rslt
  735. end function
  736. public function integer f_read (long arg_revid, ref string arg_msg);Long rslt = 1
  737. UPDATE u_email_msg
  738. SET status = '已读'
  739. Where u_email_msg.ID = :arg_revid using fj_tran;
  740. IF fj_tran.SQLCode <> 0 THEN
  741. rslt = 0
  742. arG_MSG = "更新收件标记失败~n"+fj_tran.SQLErrText
  743. GOTO ext
  744. END IF
  745. ext:
  746. IF rslt = 0 THEN
  747. ROLLBACK using fj_tran;
  748. ELSE
  749. COMMIT using fj_tran;
  750. END IF
  751. RETURN rslt
  752. end function
  753. public function long f_save (ref s_email_send arg_send, s_email_sendmx arg_sendmx[], s_email_lvfj arg_fj[], ref string arg_msg);Int rslt = 1
  754. Long i,totalSize = 0
  755. Long cnt,ll_id = 0
  756. Long ll_fjid
  757. String ls_msg
  758. Boolean has_copy = False
  759. COMMIT Using fj_tran;
  760. fj_tran.AutoCommit = True
  761. IF UpperBound(arg_fj) > 0 THEN
  762. FOR cnt = 1 To UpperBound(arg_fj)
  763. totalSize+= arg_fj[cnt].filesize
  764. IF totalSize > 100*1024*1024 THEN
  765. //附件超过100M
  766. rslt = 0
  767. arg_msg = '附件大于100m,不能发送!'
  768. GOTO ext
  769. END IF
  770. NEXT
  771. // MessageBox('',String(totalSize))
  772. END IF
  773. s_email_set s_set
  774. IF wf_ds_get_mail_set(arg_send.mailid, s_set, arg_msg) <> 1 THEN
  775. rslt = 0
  776. GOTO ext
  777. END IF
  778. arg_send.mailAddress = s_set.mailAddress
  779. arg_send.senduser = s_set.mailuser
  780. arg_send.sendaddress = s_set.mailAddress
  781. IF arg_send.NTFlag = 1 THEN
  782. arg_send.NTMail = arg_send.mailAddress
  783. END IF
  784. IF arg_send.sendid = 0 THEN
  785. ll_id = f_sys_scidentity(0,"u_email_msg","ID",arg_msg,True, commit_tran) //数据commit事务)
  786. IF ll_id <= 0 THEN
  787. rslt = 0
  788. GOTO ext
  789. END IF
  790. arg_send.boxid = wf_ds_getsendbox(arg_send.mailid)
  791. IF arg_send.boxid = -1 THEN
  792. rslt = 0
  793. arg_msg = '获取默认发件箱失败'
  794. GOTO ext
  795. END IF
  796. INSERT INTO u_email_msg
  797. ( ID,
  798. boxid,
  799. mailID,
  800. mailaddress,
  801. mailtype,
  802. Subject,
  803. Priority,
  804. // senddate,
  805. Opdate,
  806. opemp,
  807. mailsize,
  808. SendOption,
  809. textbody,
  810. htmlbody,
  811. senduser,
  812. sendaddress,
  813. ntflag,
  814. ntname,
  815. ntmail
  816. )
  817. VALUES ( :ll_id,
  818. :arg_send.boxid,
  819. :arg_send.mailID,
  820. :arg_send.mailaddress,
  821. :arg_send.mailtype,
  822. :arg_send.Subject,
  823. :arg_send.Priority,
  824. // :arg_send.senddate,
  825. getdate(),
  826. :publ_operator,
  827. :arg_send.mailsize,
  828. :arg_send.normal_flag,
  829. :arg_send.textbody,
  830. :arg_send.htmlbody,
  831. :s_set.mailuser,
  832. :s_set.mailAddress,
  833. :arg_send.ntflag,
  834. :arg_send.ntname,
  835. :arg_send.NTMail) Using fj_tran;
  836. IF fj_tran.SQLCode <> 0 THEN
  837. rslt = 0
  838. arg_msg = "插入发送邮件失败~n"+fj_tran.SQLErrText
  839. GOTO ext
  840. END IF
  841. ///////// //
  842. IF arg_send.senddate > DateTime(Today(),Now()) THEN
  843. UPDATE u_email_msg Set senddate = :arg_send.senddate,mailtype='定时发件' where ID=:ll_id Using fj_tran;
  844. END IF
  845. /////// //
  846. IF UpperBound(arg_sendmx) = 0 THEN
  847. rslt = 0
  848. arg_msg = "发送邮件收件人不能为空~n"
  849. GOTO ext
  850. END IF
  851. FOR i = 1 To UpperBound(arg_sendmx)
  852. INSERT INTO u_email_sendmx
  853. ( sendid,
  854. printid,
  855. reltype,
  856. relid,
  857. revaddress,
  858. revname ,
  859. repname,
  860. addtype)
  861. VALUES ( :ll_id,
  862. :arg_sendmx[i].printid,
  863. :arg_sendmx[i].reltype,
  864. :arg_sendmx[i].relid,
  865. :arg_sendmx[i].revaddress,
  866. :arg_sendmx[i].revname ,
  867. :arg_sendmx[i].repname,
  868. :arg_sendmx[i].addtype
  869. ) Using fj_tran;
  870. IF fj_tran.SQLCode <> 0 THEN
  871. rslt = 0
  872. arg_msg = "插入发送邮件收件人明细失败~n"+fj_tran.SQLErrText
  873. GOTO ext
  874. END IF
  875. NEXT
  876. // IF UpperBound(arg_fj.Filename) = 0 THEN GOTO ext
  877. FOR i = 1 To UpperBound(arg_fj)
  878. ll_fjid = f_sys_scidentity(0,"u_email_fj","fjid",arg_msg,True, commit_tran) //数据commit事务)
  879. IF ll_fjid <= 0 THEN
  880. rslt = 0
  881. GOTO ext
  882. END IF
  883. // DONE filesize
  884. IF arg_fj[i].FileType = C_Sys_admsg_fj THEN
  885. IF wf_admsg_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 THEN
  886. rslt = 0
  887. GOTO ext
  888. END IF
  889. ELSEIF arg_fj[i].FileType = C_u_email_fj THEN
  890. IF wf_mail_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 THEN
  891. rslt = 0
  892. GOTO ext
  893. END IF
  894. ELSEIF arg_fj[i].FileType = C_from_file THEN
  895. END IF
  896. arg_fj[i].filesize = Len(arg_fj[i].fileblob)
  897. INSERT INTO u_email_fj
  898. ( fjid,
  899. fjtype,
  900. Relid,
  901. filename,
  902. filesize,
  903. cid
  904. ) VALUES
  905. ( :ll_fjid,
  906. 0,
  907. :ll_id,
  908. :arg_fj[i].filename,
  909. :arg_fj[i].filesize,
  910. :arg_fj[i].cid
  911. ) Using fj_tran;
  912. IF fj_tran.SQLCode <> 0 THEN
  913. rslt = 0
  914. arg_msg = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  915. GOTO ext
  916. END IF
  917. IF arg_fj[i].filesize > 0 THEN
  918. COMMIT Using fj_tran;
  919. UpdateBlob u_email_fj
  920. Set fileblob = :arg_fj[i].fileblob
  921. Where fjid = :ll_fjid Using fj_tran;
  922. IF fj_tran.SQLCode <> 0 THEN
  923. rslt = 0
  924. arg_msg = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  925. GOTO ext
  926. END IF
  927. COMMIT Using fj_tran;
  928. END IF
  929. NEXT
  930. arg_send.sendid = ll_id
  931. ELSE
  932. ll_id = f_sys_scidentity(0,"u_email_msg","ID",arg_msg,True, commit_tran) //数据commit事务)
  933. IF ll_id <= 0 THEN
  934. rslt = 0
  935. GOTO ext
  936. END IF
  937. // 备份邮件
  938. INSERT INTO u_email_msg
  939. (ID, boxid, mailid, mailaddress, subject, mailsize, textbody, htmlbody, orgdata, senduser, sendaddress, sendOption, priority, senddate, opdate, opemp,
  940. revdate, tuid, mailtype, status)
  941. SELECT :ll_id AS Expr1, boxid, mailid, mailaddress, subject, mailsize, textbody, htmlbody, orgdata, senduser, sendaddress, sendOption, priority, senddate,
  942. opdate, opemp, revdate, tuid, mailtype, status
  943. FROM u_email_msg AS u_email_msg_1
  944. Where (ID = :arg_send.sendid) Using fj_tran;
  945. IF fj_tran.SQLCode <> 0 THEN
  946. rslt = 0
  947. arg_msg = '备份邮件失败,' + fj_tran.SQLErrText
  948. f_del(ll_id, ls_msg)
  949. GOTO ext
  950. END IF
  951. // 备份发件明细
  952. INSERT INTO u_email_sendmx
  953. (sendid, printid, reltype, relid, revaddress, revname, dscrp, status)
  954. SELECT :ll_id AS Expr1, printid, reltype, relid, revaddress, revname, dscrp, status
  955. FROM u_email_sendmx AS u_email_sendmx_1
  956. Where (sendid = :arg_send.sendid) Using fj_tran;
  957. IF fj_tran.SQLCode <> 0 THEN
  958. rslt = 0
  959. arg_msg = '备份邮件明细失败,' + fj_tran.SQLErrText
  960. f_del(ll_id, ls_msg)
  961. GOTO ext
  962. END IF
  963. // 备份附件
  964. Long arr_fjid[]
  965. i = 0
  966. DECLARE cur1 CURSOR FOR
  967. SELECT fjid FROM u_email_fj
  968. Where relid = :arg_send.sendid Using fj_tran;
  969. OPEN cur1;
  970. FETCH cur1 Into :ll_fjid;
  971. DO WHILE fj_tran.SQLCode = 0
  972. i++
  973. arr_fjid[i] = ll_fjid
  974. FETCH cur1 Into :ll_fjid;
  975. LOOP
  976. CLOSE cur1;
  977. FOR i = 1 To UpperBound(arr_fjid)
  978. ll_fjid = f_sys_scidentity(0,"u_email_fj","fjid",arg_msg,True, commit_tran) //数据commit事务)
  979. IF ll_fjid <= 0 THEN
  980. rslt = 0
  981. f_del(ll_id, ls_msg)
  982. GOTO ext
  983. END IF
  984. INSERT INTO u_email_fj
  985. (fjid, fjtype, Relid, filename, fileblob, filesize, filetype)
  986. SELECT :ll_fjid AS Expr1, fjtype, :ll_id, filename, fileblob, filesize, filetype
  987. FROM u_email_fj AS u_email_fj_1
  988. Where (fjid = :arr_fjid[i]) Using fj_tran;
  989. IF fj_tran.SQLCode <> 0 THEN
  990. rslt = 0
  991. arg_msg = '备份附件失败,' + fj_tran.SQLErrText
  992. f_del(ll_id, ls_msg)
  993. GOTO ext
  994. END IF
  995. NEXT
  996. has_copy = True
  997. UPDATE u_email_msg
  998. SET mailID = :arg_send.mailID,
  999. boxid = :arg_send.boxid,
  1000. mailaddress = :arg_send.mailaddress,
  1001. Subject = :arg_send.Subject,
  1002. Priority = :arg_send.Priority,
  1003. Opdate = getdate(),
  1004. opemp = :publ_operator,
  1005. mailsize = :arg_send.mailsize,
  1006. mailtype = :arg_send.mailtype,
  1007. sendOption = :arg_send.normal_flag,
  1008. textbody = :arg_send.textbody,
  1009. htmlbody = :arg_send.htmlbody,
  1010. senduser = :s_set.mailuser,
  1011. sendaddress = :s_set.mailaddress
  1012. Where ID = :ll_id Using fj_tran;
  1013. IF fj_tran.SQLCode <> 0 THEN
  1014. rslt = 0
  1015. arg_msg = "更新发送邮件失败~n"+fj_tran.SQLErrText
  1016. GOTO ext
  1017. END IF
  1018. DELETE FROM u_email_sendmx
  1019. Where sendid = :ll_id Using fj_tran;
  1020. IF fj_tran.SQLCode <> 0 THEN
  1021. rslt = 0
  1022. arg_msg = "删除发送邮件收件人明细失败~n"+fj_tran.SQLErrText
  1023. GOTO ext
  1024. END IF
  1025. IF UpperBound(arg_sendmx) = 0 THEN
  1026. rslt = 0
  1027. arg_msg = '没有收件人'
  1028. GOTO ext
  1029. END IF
  1030. FOR i = 1 To UpperBound(arg_sendmx)
  1031. INSERT INTO u_email_sendmx
  1032. ( sendid,
  1033. printid,
  1034. reltype,
  1035. relid,
  1036. revaddress,
  1037. revname ,
  1038. addtype
  1039. )
  1040. VALUES ( :ll_id,
  1041. :arg_sendmx[i].printid,
  1042. :arg_sendmx[i].reltype,
  1043. :arg_sendmx[i].relid,
  1044. :arg_sendmx[i].revaddress,
  1045. :arg_sendmx[i].revname,
  1046. :arg_sendmx[i].addtype
  1047. ) Using fj_tran ;
  1048. IF fj_tran.SQLCode <> 0 THEN
  1049. rslt = 0
  1050. arg_msg = "插入发送邮件收件人明细失败~n"+fj_tran.SQLErrText
  1051. GOTO ext
  1052. END IF
  1053. NEXT
  1054. DELETE FROM u_email_fj
  1055. Where relid = :ll_id Using fj_tran;
  1056. IF fj_tran.SQLCode <> 0 THEN
  1057. rslt = 0
  1058. arg_msg = "删除发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  1059. GOTO ext
  1060. END IF
  1061. // IF UpperBound(arg_fj.Filename) = 0 THEN GOTO ext
  1062. FOR i = 1 To UpperBound(arg_fj)
  1063. ll_fjid = f_sys_scidentity(0,"u_email_fj","fjid",arg_msg,True, commit_tran) //数据commit事务)
  1064. IF ll_fjid <= 0 THEN
  1065. rslt = 0
  1066. GOTO ext
  1067. END IF
  1068. // DONE filesize
  1069. IF arg_fj[i].FileType = C_Sys_admsg_fj THEN
  1070. IF wf_admsg_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 THEN
  1071. rslt = 0
  1072. GOTO ext
  1073. END IF
  1074. ELSEIF arg_fj[i].FileType = C_u_email_fj THEN
  1075. IF wf_mail_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 THEN
  1076. rslt = 0
  1077. GOTO ext
  1078. END IF
  1079. ELSEIF arg_fj[i].FileType = C_from_file THEN
  1080. END IF
  1081. arg_fj[i].filesize = Len(arg_fj[i].fileblob)
  1082. //////////// //
  1083. INSERT INTO u_email_fj
  1084. ( fjid,
  1085. fjtype,
  1086. Relid,
  1087. filename,
  1088. filesize,
  1089. cid
  1090. ) VALUES
  1091. ( :ll_fjid,
  1092. 0,
  1093. :ll_id,
  1094. :arg_fj[i].filename,
  1095. :arg_fj[i].filesize,
  1096. :arg_fj[i].cid
  1097. ) Using fj_tran;
  1098. IF fj_tran.SQLCode <> 0 THEN
  1099. rslt = 0
  1100. arg_msg = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  1101. GOTO ext
  1102. ELSE
  1103. COMMIT Using fj_tran;
  1104. END IF
  1105. IF arg_fj[i].filesize > 0 THEN
  1106. UpdateBlob u_email_fj
  1107. Set fileblob = :arg_fj[i].fileblob
  1108. Where fjid = :ll_fjid Using fj_tran;
  1109. IF fj_tran.SQLCode <> 0 THEN
  1110. rslt = 0
  1111. arg_msg = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  1112. GOTO ext
  1113. END IF
  1114. END IF
  1115. NEXT
  1116. fj_tran.AutoCommit = False
  1117. f_del(arg_send.sendid, ls_msg)
  1118. f_change_id(ll_id, arg_send.sendid, ls_msg)
  1119. END IF
  1120. ext:
  1121. fj_tran.AutoCommit = False
  1122. IF rslt = 0 THEN
  1123. IF arg_send.sendid = 0 And ll_id > 0 THEN
  1124. f_del(ll_id, ls_msg)
  1125. END IF
  1126. IF has_copy And arg_send.sendid > 0 THEN
  1127. f_del(ll_id, ls_msg)
  1128. END IF
  1129. ELSE
  1130. END IF
  1131. RETURN rslt
  1132. end function
  1133. public function long f_import_eml (ref s_email_send arg_send, s_email_lvfj arg_fj[], ref string arg_msg);Int rslt = 1
  1134. Long i
  1135. Long cnt,ll_id = 0
  1136. long ll_fjid
  1137. string ls_msg
  1138. IF arg_send.sendid = 0 THEN
  1139. ll_id = f_sys_scidentity(0,"u_email_msg","ID",arG_MSG,TRUE, commit_tran) //数据commit事务)
  1140. IF ll_id <= 0 THEN
  1141. rslt = 0
  1142. GOTO ext
  1143. END IF
  1144. INSERT INTO u_email_msg
  1145. ( ID,
  1146. boxid,
  1147. mailID,
  1148. mailaddress,
  1149. mailtype,
  1150. Subject,
  1151. Priority,
  1152. // senddate,
  1153. Opdate,
  1154. opemp,
  1155. mailsize,
  1156. SendOption,
  1157. textbody,
  1158. htmlbody,
  1159. senduser,
  1160. sendaddress,
  1161. status,
  1162. revdate)
  1163. VALUES ( :ll_id,
  1164. :arg_send.boxid,
  1165. :arg_send.mailID,
  1166. :arg_send.mailaddress,
  1167. :arg_send.mailtype,
  1168. :arg_send.Subject,
  1169. :arg_send.Priority,
  1170. // :arg_send.senddate,
  1171. getdate(),
  1172. :publ_operator,
  1173. :arg_send.mailsize,
  1174. :arg_send.normal_flag,
  1175. :arg_send.textbody,
  1176. :arg_send.htmlbody,
  1177. :arg_send.senduser,
  1178. :arg_send.sendaddress,
  1179. :arg_send.status,
  1180. GETDATE()) USING fj_tran;
  1181. IF fj_tran.SQLCode <> 0 THEN
  1182. rslt = 0
  1183. arG_MSG = "插入发送邮件失败~n"+fj_tran.SQLErrText
  1184. GOTO ext
  1185. END IF
  1186. commit using fj_tran;
  1187. UPDATEBLOB u_email_msg set orgdata = :arg_send.orgdata WHERE id = :ll_id using fj_tran;
  1188. if fj_tran.sqlcode <> 0 then
  1189. rslt = 0
  1190. arg_msg = '更新原始数据失败,' + fj_tran.sqlerrtext
  1191. goto ext
  1192. end if
  1193. commit using fj_tran;
  1194. // IF UpperBound(arg_fj.Filename) = 0 THEN GOTO ext
  1195. FOR i = 1 TO UpperBound(arg_fj)
  1196. ll_fjid = f_sys_scidentity(0,"u_email_fj","fjid",arG_MSG,TRUE, commit_tran) //数据commit事务)
  1197. IF ll_fjid <= 0 THEN
  1198. rslt = 0
  1199. GOTO ext
  1200. END IF
  1201. // DONE filesize
  1202. if arg_fj[i].filetype = C_Sys_admsg_fj then
  1203. if wf_admsg_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 then
  1204. rslt = 0
  1205. goto ext
  1206. end if
  1207. elseif arg_fj[i].filetype = C_u_email_fj then
  1208. if wf_mail_getfjblob(arg_fj[i].fjid, arg_fj[i].fileblob, arg_msg) <> 1 then
  1209. rslt = 0
  1210. goto ext
  1211. end if
  1212. elseif arg_fj[i].filetype = C_from_file then
  1213. end if
  1214. arg_fj[i].filesize = len(arg_fj[i].fileblob)
  1215. INSERT INTO u_email_fj
  1216. ( fjid,
  1217. fjtype,
  1218. Relid,
  1219. filename,
  1220. filesize,
  1221. cid
  1222. ) VALUES
  1223. ( :ll_fjid,
  1224. 0,
  1225. :ll_id,
  1226. :arg_fj[i].filename,
  1227. :arg_fj[i].filesize,
  1228. :arg_fj[i].cid
  1229. ) USING fj_tran;
  1230. IF fj_tran.SQLCode <> 0 THEN
  1231. rslt = 0
  1232. arG_MSG = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  1233. GOTO ext
  1234. END IF
  1235. IF arg_fj[i].filesize > 0 THEN
  1236. COMMIT USING fj_tran;
  1237. UPDATEBLOB u_email_fj
  1238. Set fileblob = :arg_fj[i].fileblob
  1239. Where fjid = :ll_fjid USING fj_tran;
  1240. IF fj_tran.SQLCode <> 0 THEN
  1241. rslt = 0
  1242. arG_MSG = "插入发送邮件的附件明细失败~n"+fj_tran.SQLErrText
  1243. GOTO ext
  1244. END IF
  1245. Commit using fj_tran;
  1246. END IF
  1247. NEXT
  1248. arg_send.sendid = ll_id
  1249. ELSE
  1250. rslt = 0
  1251. arg_msg = '导入邮件必须新建邮件'
  1252. goto ext
  1253. END IF
  1254. ext:
  1255. IF rslt = 0 THEN
  1256. ROLLBACK USING commit_tran;
  1257. ROLLBACK USING fj_tran;
  1258. if arg_send.sendid = 0 AND ll_id > 0 then
  1259. f_del(ll_id, ls_msg)
  1260. end if
  1261. ELSE
  1262. COMMIT USING commit_tran;
  1263. COMMIT USING fj_tran;
  1264. END IF
  1265. RETURN rslt
  1266. end function
  1267. public function integer f_change_id (long arg_fromid, long arg_toid, ref string arg_msg);int rslt = 1
  1268. UPDATE u_email_msg SET ID = :arg_toid WHERE ID = :arg_fromid using fj_tran;
  1269. if fj_tran.sqlcode <> 0 then
  1270. rslt = 0
  1271. arg_msg = '更新邮件ID失败,' + fj_tran.sqlerrtext
  1272. goto ext
  1273. end if
  1274. UPDATE u_email_sendmx SET sendid = :arg_toid WHERE sendid = :arg_fromid using fj_tran;
  1275. if fj_tran.sqlcode <> 0 then
  1276. rslt = 0
  1277. arg_msg = '更新邮件明细sendid失败,' + fj_tran.sqlerrtext
  1278. goto ext
  1279. end if
  1280. UPDATE u_email_fj SET Relid = :arg_toid WHERE Relid = :arg_fromid using fj_tran;
  1281. if fj_tran.sqlcode <> 0 then
  1282. rslt = 0
  1283. arg_msg = '更新附件相关失败,' + fj_tran.sqlerrtext
  1284. goto ext
  1285. end if
  1286. ext:
  1287. if rslt = 0 then
  1288. rollback using fj_tran;
  1289. else
  1290. commit using fj_tran;
  1291. end if
  1292. return rslt
  1293. end function
  1294. on uo_email.create
  1295. call super::create
  1296. TriggerEvent( this, "constructor" )
  1297. end on
  1298. on uo_email.destroy
  1299. TriggerEvent( this, "destructor" )
  1300. call super::destroy
  1301. end on