BlogController.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. package controllers
  2. import (
  3. "strings"
  4. "github.com/lifei6671/mindoc/models"
  5. "time"
  6. "github.com/astaxie/beego"
  7. "github.com/lifei6671/mindoc/conf"
  8. "github.com/lifei6671/mindoc/utils/pagination"
  9. "strconv"
  10. "fmt"
  11. "os"
  12. "net/http"
  13. "path/filepath"
  14. "github.com/astaxie/beego/orm"
  15. "html/template"
  16. "encoding/json"
  17. "github.com/lifei6671/mindoc/utils"
  18. )
  19. type BlogController struct{
  20. BaseController
  21. }
  22. //文章阅读
  23. func (c *BlogController) Index() {
  24. c.Prepare()
  25. c.TplName = "blog/index.tpl"
  26. blogId,_ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  27. if blogId <= 0{
  28. c.ShowErrorPage(404,"页面不存在")
  29. }
  30. blogReadSession := fmt.Sprintf("blog:read:%d",blogId)
  31. blog,err := models.NewBlog().FindFromCache(blogId)
  32. if err != nil {
  33. c.ShowErrorPage(404,"文章不存在")
  34. }
  35. if c.Ctx.Input.IsPost() {
  36. password := c.GetString("password");
  37. if blog.BlogStatus == "password" && password != blog.Password {
  38. c.JsonResult(6001,"文章密码不正确")
  39. }else if blog.BlogStatus == "password" && password == blog.Password {
  40. //如果密码输入正确,则存入session中
  41. c.CruSession.Set(blogReadSession,blogId)
  42. c.JsonResult(0,"OK")
  43. }
  44. c.JsonResult(0,"OK")
  45. }else if blog.BlogStatus == "password" && c.CruSession.Get(blogReadSession) == nil {
  46. //如果不存在已输入密码的标记
  47. c.TplName = "blog/index_password.tpl"
  48. }
  49. //加载文章附件
  50. blog.LinkAttach();
  51. c.Data["Model"] = blog
  52. c.Data["Content"] = template.HTML(blog.BlogRelease)
  53. if blog.BlogExcerpt == "" {
  54. c.Data["Description"] = utils.AutoSummary(blog.BlogRelease,120)
  55. }else{
  56. c.Data["Description"] = blog.BlogExcerpt
  57. }
  58. if nextBlog,err := models.NewBlog().QueryNext(blogId);err == nil {
  59. c.Data["Next"] = nextBlog
  60. }
  61. if preBlog,err := models.NewBlog().QueryPrevious(blogId);err == nil {
  62. c.Data["Previous"] = preBlog
  63. }
  64. }
  65. //文章列表
  66. func (c *BlogController) List() {
  67. c.Prepare()
  68. c.TplName = "blog/list.tpl"
  69. pageIndex, _ := c.GetInt("page", 1)
  70. var blogList []*models.Blog
  71. var totalCount int
  72. var err error
  73. blogList,totalCount,err = models.NewBlog().FindToPager(pageIndex,conf.PageSize,0,"")
  74. if err != nil && err != orm.ErrNoRows {
  75. c.ShowErrorPage(500,err.Error())
  76. }
  77. if totalCount > 0 {
  78. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  79. c.Data["PageHtml"] = pager.HtmlPages()
  80. for _,blog := range blogList {
  81. //如果没有添加文章摘要,则自动提取
  82. if blog.BlogExcerpt == "" {
  83. blog.BlogExcerpt = utils.AutoSummary(blog.BlogRelease,120)
  84. }
  85. blog.Link()
  86. }
  87. } else {
  88. c.Data["PageHtml"] = ""
  89. }
  90. c.Data["Lists"] = blogList
  91. }
  92. //管理后台文章列表
  93. func (c *BlogController) ManageList() {
  94. c.Prepare()
  95. c.TplName = "blog/manage_list.tpl"
  96. pageIndex, _ := c.GetInt("page", 1)
  97. blogList,totalCount,err := models.NewBlog().FindToPager(pageIndex,conf.PageSize,c.Member.MemberId,"")
  98. if err != nil {
  99. c.ShowErrorPage(500,err.Error())
  100. }
  101. if totalCount > 0 {
  102. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  103. c.Data["PageHtml"] = pager.HtmlPages()
  104. } else {
  105. c.Data["PageHtml"] = ""
  106. }
  107. c.Data["ModelList"] = blogList
  108. }
  109. //文章设置
  110. func (c *BlogController) ManageSetting() {
  111. c.Prepare()
  112. c.TplName = "blog/manage_setting.tpl"
  113. //如果是post请求
  114. if c.Ctx.Input.IsPost() {
  115. blogId,_ := c.GetInt("id",0)
  116. blogTitle := c.GetString("title")
  117. blogIdentify := c.GetString("identify")
  118. orderIndex,_ := c.GetInt("order_index",0)
  119. blogType,_ := c.GetInt("blog_type",0)
  120. blogExcerpt := c.GetString("excerpt","")
  121. blogStatus := c.GetString("status","publish")
  122. blogPassword := c.GetString("password","")
  123. documentIdentify := strings.TrimSpace(c.GetString("documentIdentify"))
  124. bookIdentify := strings.TrimSpace(c.GetString("bookIdentify"))
  125. documentId := 0
  126. if blogTitle == "" {
  127. c.JsonResult(6001,"文章标题不能为空")
  128. }
  129. if strings.Count(blogExcerpt,"") > 500 {
  130. c.JsonResult(6008,"文章摘要必须小于500字符")
  131. }
  132. if blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" {
  133. blogStatus = "public"
  134. }
  135. if blogStatus == "password" && blogPassword == "" {
  136. c.JsonResult(6010,"加密文章请设置密码")
  137. }
  138. if blogType != 0 && blogType != 1 {
  139. c.JsonResult(6005,"未知的文章类型")
  140. }
  141. if strings.Count(blogTitle,"") > 200 {
  142. c.JsonResult(6002,"文章标题不能大于200个字符")
  143. }
  144. //如果是关联文章,需要同步关联的文档
  145. if blogType == 1 {
  146. book,err := models.NewBook().FindByIdentify(bookIdentify)
  147. if err != nil {
  148. c.JsonResult(6011,"关联文档的项目不存在")
  149. }
  150. doc,err := models.NewDocument().FindByIdentityFirst(documentIdentify,book.BookId)
  151. if err != nil {
  152. c.JsonResult(6003,"查询关联项目文档时出错")
  153. }
  154. documentId = doc.DocumentId
  155. // 如果不是超级管理员,则校验权限
  156. if !c.Member.IsAdministrator() {
  157. bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
  158. if err != nil || bookResult.RoleId == conf.BookObserver {
  159. c.JsonResult(6002, "关联文档不存在或权限不足")
  160. }
  161. }
  162. }
  163. var blog *models.Blog
  164. var err error
  165. //如果文章ID存在,则从数据库中查询文章
  166. if blogId > 0 {
  167. if c.Member.IsAdministrator() {
  168. blog, err = models.NewBlog().Find(blogId)
  169. } else {
  170. blog, err = models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
  171. }
  172. if err != nil {
  173. c.JsonResult(6003, "文章不存在")
  174. }
  175. //如果设置了文章标识
  176. if blogIdentify != "" {
  177. //如果查询到的文章标识存在并且不是当前文章的id
  178. if b,err := models.NewBlog().FindByIdentify(blogIdentify); err == nil && b.BlogId != blogId {
  179. c.JsonResult(6004,"文章标识已存在")
  180. }
  181. }
  182. blog.Modified = time.Now()
  183. blog.ModifyAt = c.Member.MemberId
  184. }else{
  185. //如果设置了文章标识
  186. if blogIdentify != "" {
  187. if models.NewBlog().IsExist(blogIdentify) {
  188. c.JsonResult(6004,"文章标识已存在")
  189. }
  190. }
  191. blog = models.NewBlog()
  192. blog.MemberId = c.Member.MemberId
  193. blog.Created = time.Now()
  194. }
  195. if blogIdentify == "" {
  196. blog.BlogIdentify = fmt.Sprintf("%s-%d","post",time.Now().UnixNano())
  197. }else{
  198. blog.BlogIdentify = blogIdentify
  199. }
  200. blog.BlogTitle = blogTitle
  201. blog.OrderIndex = orderIndex
  202. blog.BlogType = blogType
  203. if blogType == 1 {
  204. blog.DocumentId = documentId
  205. }
  206. blog.BlogExcerpt = blogExcerpt
  207. blog.BlogStatus = blogStatus
  208. blog.Password = blogPassword
  209. if err := blog.Save();err != nil {
  210. beego.Error("保存文章失败 -> ",err)
  211. c.JsonResult(6011,"保存文章失败")
  212. }else{
  213. c.JsonResult(0,"ok",blog)
  214. }
  215. }
  216. if c.Ctx.Input.Referer() == "" {
  217. c.Data["Referer"] = "javascript:history.back();"
  218. }else{
  219. c.Data["Referer"] = c.Ctx.Input.Referer()
  220. }
  221. blogId,err := strconv.Atoi(c.Ctx.Input.Param(":id"))
  222. c.Data["DocumentIdentify"] = "";
  223. if err == nil {
  224. blog,err := models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  225. if err != nil {
  226. c.ShowErrorPage(500,err.Error())
  227. }
  228. c.Data["Model"] = blog
  229. }else{
  230. c.Data["Model"] = models.NewBlog()
  231. }
  232. }
  233. //文章创建或编辑
  234. func (c *BlogController) ManageEdit() {
  235. c.Prepare()
  236. c.TplName = "blog/manage_edit.tpl"
  237. if c.Ctx.Input.IsPost() {
  238. blogId,_ := c.GetInt("blogId",0)
  239. if blogId <= 0 {
  240. c.JsonResult(6001,"文章参数错误")
  241. }
  242. blogContent := c.GetString("content","")
  243. blogHtml := c.GetString("htmlContent","")
  244. version,_ := c.GetInt64("version",0)
  245. cover := c.GetString("cover")
  246. var blog *models.Blog
  247. var err error
  248. if c.Member.IsAdministrator() {
  249. blog,err = models.NewBlog().Find(blogId)
  250. }else{
  251. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  252. }
  253. if err != nil {
  254. beego.Error("查询文章失败 ->",err)
  255. c.JsonResult(6002,"查询文章失败")
  256. }
  257. if version > 0 && blog.Version != version && cover != "yes"{
  258. c.JsonResult(6005,"文章已被修改")
  259. }
  260. //如果是关联文章,需要同步关联的文档
  261. if blog.BlogType == 1 {
  262. doc,err := models.NewDocument().Find(blog.DocumentId)
  263. if err != nil {
  264. beego.Error("查询关联项目文档时出错 ->", err)
  265. c.JsonResult(6003,"查询关联项目文档时出错")
  266. }
  267. book, err := models.NewBook().Find(doc.BookId)
  268. if err != nil {
  269. c.JsonResult(6002, "项目不存在或权限不足")
  270. }
  271. // 如果不是超级管理员,则校验权限
  272. if !c.Member.IsAdministrator() {
  273. bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
  274. if err != nil || bookResult.RoleId == conf.BookObserver {
  275. beego.Error("FindByIdentify => ", err)
  276. c.JsonResult(6002, "关联文档不存在或权限不足")
  277. }
  278. }
  279. doc.Markdown = blogContent
  280. doc.Release = blogHtml
  281. doc.Content = blogHtml
  282. doc.ModifyTime = time.Now()
  283. doc.ModifyAt = c.Member.MemberId
  284. if err := doc.InsertOrUpdate("markdown","release","content","modify_time","modify_at");err != nil {
  285. beego.Error("保存关联文档时出错 ->",err)
  286. c.JsonResult(6004,"保存关联文档时出错")
  287. }
  288. }
  289. blog.BlogContent = blogContent
  290. blog.BlogRelease = blogHtml
  291. blog.ModifyAt = c.Member.MemberId
  292. blog.Modified = time.Now()
  293. if err := blog.Save("blog_content","blog_release","modify_at","modify_time","version");err != nil {
  294. beego.Error("保存文章失败 -> ",err)
  295. c.JsonResult(6011,"保存文章失败")
  296. }else{
  297. c.JsonResult(0,"ok",blog)
  298. }
  299. }
  300. blogId,_ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  301. if blogId <= 0 {
  302. c.ShowErrorPage(500,"参数错误")
  303. }
  304. var blog *models.Blog
  305. var err error
  306. if c.Member.IsAdministrator() {
  307. blog,err = models.NewBlog().Find(blogId)
  308. }else{
  309. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  310. }
  311. if err != nil {
  312. c.ShowErrorPage(404,"文章不存在或已删除")
  313. }
  314. blog.LinkAttach()
  315. if len(blog.AttachList) > 0 {
  316. returnJSON, err := json.Marshal(blog.AttachList)
  317. if err != nil {
  318. beego.Error("序列化文章附件时出错 ->",err)
  319. }else{
  320. c.Data["AttachList"] = template.JS(string(returnJSON))
  321. }
  322. }else{
  323. c.Data["AttachList"] = template.JS("[]")
  324. }
  325. c.Data["Model"] = blog
  326. }
  327. //删除文章
  328. func (c *BlogController) ManageDelete() {
  329. c.Prepare()
  330. blogId,_ := c.GetInt("blog_id",0)
  331. if blogId <= 0 {
  332. c.JsonResult(6001,"参数错误")
  333. }
  334. var blog *models.Blog
  335. var err error
  336. if c.Member.IsAdministrator() {
  337. blog,err = models.NewBlog().Find(blogId)
  338. }else{
  339. blog,err = models.NewBlog().FindByIdAndMemberId(blogId,c.Member.MemberId)
  340. }
  341. if err != nil {
  342. c.JsonResult(6002,"文章不存在或已删除")
  343. }
  344. if err := blog.Delete(blogId); err != nil {
  345. c.JsonResult(6003,"删除失败")
  346. }else{
  347. c.JsonResult(0,"删除成功")
  348. }
  349. }
  350. // 上传附件或图片
  351. func (c *BlogController) Upload() {
  352. blogId, _ := c.GetInt("blogId")
  353. if blogId <= 0 {
  354. c.JsonResult(6001, "参数错误")
  355. }
  356. blog,err := models.NewBlog().Find(blogId)
  357. if err != nil {
  358. c.JsonResult(6010,"文章不存在")
  359. }
  360. if !c.Member.IsAdministrator() && blog.MemberId != c.Member.MemberId {
  361. c.JsonResult(6011,"没有文章的访问权限")
  362. }
  363. name := "editormd-file-file"
  364. file, moreFile, err := c.GetFile(name)
  365. if err == http.ErrMissingFile {
  366. name = "editormd-image-file"
  367. file, moreFile, err = c.GetFile(name)
  368. if err == http.ErrMissingFile {
  369. c.JsonResult(6003, "没有发现需要上传的图片")
  370. }
  371. }
  372. if err != nil {
  373. c.JsonResult(6002, err.Error())
  374. }
  375. defer file.Close()
  376. type Size interface {
  377. Size() int64
  378. }
  379. if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
  380. c.JsonResult(6009, "查过文件允许的上传最大值")
  381. }
  382. ext := filepath.Ext(moreFile.Filename)
  383. if ext == "" {
  384. c.JsonResult(6003, "无法解析文件的格式")
  385. }
  386. //如果文件类型设置为 * 标识不限制文件类型
  387. if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" {
  388. if !conf.IsAllowUploadFileExt(ext) {
  389. c.JsonResult(6004, "不允许的文件类型")
  390. }
  391. }
  392. // 如果是超级管理员,则不判断权限
  393. if c.Member.IsAdministrator() {
  394. _, err := models.NewBlog().Find(blogId)
  395. if err != nil {
  396. c.JsonResult(6006, "文档不存在或权限不足")
  397. }
  398. } else {
  399. _, err := models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
  400. if err != nil {
  401. beego.Error("查询文章时出错 -> ", err)
  402. if err == orm.ErrNoRows {
  403. c.JsonResult(6006, "权限不足")
  404. }
  405. c.JsonResult(6001, err.Error())
  406. }
  407. }
  408. fileName := "attach_" + strconv.FormatInt(time.Now().UnixNano(), 16)
  409. filePath := filepath.Join(conf.WorkingDirectory, "uploads", "blog", time.Now().Format("200601"), fileName+ext)
  410. path := filepath.Dir(filePath)
  411. os.MkdirAll(path, os.ModePerm)
  412. err = c.SaveToFile(name, filePath)
  413. if err != nil {
  414. beego.Error("SaveToFile => ", err)
  415. c.JsonResult(6005, "保存文件失败")
  416. }
  417. var httpPath string
  418. result := make(map[string]interface{})
  419. //如果是图片,则当做内置图片处理,否则当做附件处理
  420. if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
  421. httpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
  422. if strings.HasPrefix(httpPath, "//") {
  423. httpPath = conf.URLForWithCdnImage(string(httpPath[1:]))
  424. }
  425. } else {
  426. attachment := models.NewAttachment()
  427. attachment.BookId = 0
  428. attachment.FileName = moreFile.Filename
  429. attachment.CreateAt = c.Member.MemberId
  430. attachment.FileExt = ext
  431. attachment.FilePath = strings.TrimPrefix(filePath, conf.WorkingDirectory)
  432. attachment.DocumentId = blogId
  433. //如果是关联文章,则将附件设置为关联文档的文档上
  434. if blog.BlogType == 1 {
  435. attachment.BookId = blog.BookId
  436. attachment.DocumentId = blog.DocumentId
  437. }
  438. if fileInfo, err := os.Stat(filePath); err == nil {
  439. attachment.FileSize = float64(fileInfo.Size())
  440. }
  441. attachment.HttpPath = httpPath
  442. if err := attachment.Insert(); err != nil {
  443. os.Remove(filePath)
  444. beego.Error("保存文件附件失败 => ", err)
  445. c.JsonResult(6006, "文件保存失败")
  446. }
  447. if attachment.HttpPath == "" {
  448. attachment.HttpPath = conf.URLFor("BlogController.Download", ":id", blogId, ":attach_id", attachment.AttachmentId)
  449. if err := attachment.Update(); err != nil {
  450. beego.Error("SaveToFile => ", err)
  451. c.JsonResult(6005, "保存文件失败")
  452. }
  453. }
  454. result["attach"] = attachment
  455. }
  456. result["errcode"] = 0
  457. result["success"] = 1
  458. result["message"] = "ok"
  459. result["url"] = httpPath
  460. result["alt"] = fileName
  461. c.Ctx.Output.JSON(result, true, false)
  462. c.StopRun()
  463. }
  464. // 删除附件
  465. func (c *BlogController) RemoveAttachment() {
  466. c.Prepare()
  467. attachId, _ := c.GetInt("attach_id")
  468. blogId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  469. if attachId <= 0 {
  470. c.JsonResult(6001, "参数错误")
  471. }
  472. blog, err := models.NewBlog().Find(blogId)
  473. if err != nil {
  474. if err == orm.ErrNoRows {
  475. c.ShowErrorPage(500, "文档不存在")
  476. } else {
  477. c.ShowErrorPage(500, "查询文章时异常")
  478. }
  479. }
  480. attach, err := models.NewAttachment().Find(attachId)
  481. if err != nil {
  482. beego.Error(err)
  483. c.JsonResult(6002, "附件不存在")
  484. }
  485. if !c.Member.IsAdministrator() {
  486. _, err := models.NewBlog().FindByIdAndMemberId(attach.DocumentId,c.Member.MemberId)
  487. if err != nil {
  488. beego.Error(err)
  489. c.JsonResult(6003, "文档不存在")
  490. }
  491. }
  492. if blog.BlogType == 1 && attach.BookId != blog.BookId && attach.DocumentId != blog.DocumentId {
  493. c.ShowErrorPage(404,"附件不存在")
  494. }else if attach.BookId !=0 || attach.DocumentId != blogId {
  495. c.ShowErrorPage(404,"附件不存在")
  496. }
  497. if err := attach.Delete();err != nil {
  498. beego.Error(err)
  499. c.JsonResult(6005, "删除失败")
  500. }
  501. os.Remove(filepath.Join(conf.WorkingDirectory, attach.FilePath))
  502. c.JsonResult(0, "ok", attach)
  503. }
  504. //下载附件
  505. func (c *BlogController) Download() {
  506. c.Prepare()
  507. blogId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  508. attachId, _ := strconv.Atoi(c.Ctx.Input.Param(":attach_id"))
  509. password := c.GetString("password")
  510. blog, err := models.NewBlog().Find(blogId)
  511. if err != nil {
  512. if err == orm.ErrNoRows {
  513. c.ShowErrorPage(500, "文档不存在")
  514. } else {
  515. c.ShowErrorPage(500, "查询文章时异常")
  516. }
  517. }
  518. blogReadSession := fmt.Sprintf("blog:read:%d",blogId)
  519. if (c.Member != nil && !c.Member.IsAdministrator()) || ( blog.BlogStatus == "password" && password != blog.Password && c.CruSession.Get(blogReadSession) == nil) {
  520. c.ShowErrorPage(403, "没有下载权限")
  521. }
  522. // 查找附件
  523. attachment, err := models.NewAttachment().Find(attachId)
  524. if err != nil {
  525. beego.Error("DownloadAttachment => ", err)
  526. if err == orm.ErrNoRows {
  527. c.ShowErrorPage(404,"附件不存在")
  528. } else {
  529. c.ShowErrorPage(500,"查询附件时出现异常")
  530. }
  531. }
  532. if blog.BlogType == 1 && attachment.BookId != blog.BookId && attachment.DocumentId != blog.DocumentId {
  533. c.ShowErrorPage(404,"附件不存在")
  534. }else if attachment.BookId !=0 || attachment.DocumentId != blogId {
  535. c.ShowErrorPage(404,"附件不存在")
  536. }
  537. c.Ctx.Output.Download(filepath.Join(conf.WorkingDirectory, attachment.FilePath), attachment.FileName)
  538. c.StopRun()
  539. }