db.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of gostfix project https://git.semlanik.org/semlanik/gostfix
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. package db
  26. import (
  27. "context"
  28. "crypto/sha1"
  29. "encoding/hex"
  30. "errors"
  31. "fmt"
  32. "log"
  33. "os"
  34. "strings"
  35. "sync"
  36. "time"
  37. common "git.semlanik.org/semlanik/gostfix/common"
  38. "git.semlanik.org/semlanik/gostfix/utils"
  39. "github.com/semlanik/berkeleydb"
  40. bcrypt "golang.org/x/crypto/bcrypt"
  41. bson "go.mongodb.org/mongo-driver/bson"
  42. "go.mongodb.org/mongo-driver/bson/primitive"
  43. mongo "go.mongodb.org/mongo-driver/mongo"
  44. options "go.mongodb.org/mongo-driver/mongo/options"
  45. config "git.semlanik.org/semlanik/gostfix/config"
  46. )
  47. type StuctNotifiers struct {
  48. notifiers []common.Notifier
  49. notifiersLock sync.Mutex
  50. }
  51. var notifiers StuctNotifiers = StuctNotifiers{
  52. notifiers: []common.Notifier{},
  53. }
  54. type Storage struct {
  55. db *mongo.Database
  56. usersCollection *mongo.Collection
  57. tokensCollection *mongo.Collection
  58. emailsCollection *mongo.Collection
  59. allEmailsCollection *mongo.Collection
  60. }
  61. func qualifiedMailCollection(user string) string {
  62. sum := sha1.Sum([]byte(user))
  63. return "mb" + hex.EncodeToString(sum[:])
  64. }
  65. func NewStorage() (s *Storage, err error) {
  66. fullUrl := "mongodb://"
  67. if config.ConfigInstance().MongoUser != "" {
  68. fullUrl += config.ConfigInstance().MongoUser
  69. if config.ConfigInstance().MongoPassword != "" {
  70. fullUrl += ":" + config.ConfigInstance().MongoPassword
  71. }
  72. fullUrl += "@"
  73. }
  74. fullUrl += config.ConfigInstance().MongoAddress
  75. client, err := mongo.NewClient(options.Client().ApplyURI(fullUrl))
  76. if err != nil {
  77. return nil, err
  78. }
  79. ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
  80. defer cancel()
  81. err = client.Connect(ctx)
  82. if err != nil {
  83. return nil, err
  84. }
  85. db := client.Database("gostfix")
  86. index := mongo.IndexModel{
  87. Keys: bson.M{
  88. "user": 1,
  89. },
  90. Options: options.Index().SetUnique(true),
  91. }
  92. s = &Storage{
  93. db: db,
  94. usersCollection: db.Collection("users"),
  95. tokensCollection: db.Collection("tokens"),
  96. emailsCollection: db.Collection("emails"),
  97. allEmailsCollection: db.Collection("allEmails"),
  98. }
  99. //Initial database setup
  100. s.usersCollection.Indexes().CreateOne(context.Background(), index)
  101. s.tokensCollection.Indexes().CreateOne(context.Background(), index)
  102. s.emailsCollection.Indexes().CreateOne(context.Background(), index)
  103. return
  104. }
  105. func (s *Storage) AddUser(user, password, fullName string) error {
  106. hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
  107. if err != nil {
  108. return err
  109. }
  110. hashString := string(hash)
  111. userInfo := bson.M{
  112. "user": user,
  113. "password": hashString,
  114. "fullName": fullName,
  115. }
  116. _, err = s.usersCollection.InsertOne(context.Background(), userInfo)
  117. if err != nil {
  118. return err
  119. }
  120. err = s.addEmail(user, user, true)
  121. if err != nil {
  122. s.usersCollection.DeleteOne(context.Background(), bson.M{"user": user})
  123. return err
  124. }
  125. return nil
  126. }
  127. func (s *Storage) UpdateUser(user, password, fullName string) error {
  128. userInfo := bson.M{}
  129. if len(password) > 0 && len(password) < 128 {
  130. hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
  131. if err != nil {
  132. return err
  133. }
  134. hashString := string(hash)
  135. userInfo["password"] = hashString
  136. }
  137. if len(fullName) > 0 && len(fullName) < 128 && utils.RegExpUtilsInstance().FullNameChecker.MatchString(fullName) {
  138. userInfo["fullName"] = fullName
  139. }
  140. if len(userInfo) > 0 {
  141. _, err := s.usersCollection.UpdateOne(context.Background(), bson.M{"user": user}, bson.M{"$set": userInfo})
  142. if err != nil {
  143. return err
  144. }
  145. }
  146. return nil
  147. }
  148. func (s *Storage) AddEmail(user string, email string) error {
  149. return s.addEmail(user, email, false)
  150. }
  151. func (s *Storage) addEmail(user string, email string, upsert bool) error {
  152. result := struct {
  153. User string
  154. }{}
  155. err := s.usersCollection.FindOne(context.Background(), bson.M{"user": user}).Decode(&result)
  156. if err != nil {
  157. return err
  158. }
  159. emails, err := s.GetAllEmails()
  160. if err != nil {
  161. return err
  162. }
  163. for _, existingEmail := range emails {
  164. if existingEmail == email {
  165. return errors.New("Email exists")
  166. }
  167. }
  168. emailParts := strings.Split(email, "@")
  169. if len(emailParts) != 2 {
  170. return errors.New("Invalid email format")
  171. }
  172. db, err := berkeleydb.NewDB()
  173. if err != nil {
  174. log.Fatal(err)
  175. }
  176. err = db.Open(config.ConfigInstance().VMailboxMaps, berkeleydb.DbHash, 0)
  177. if err != nil {
  178. log.Fatalf("Unable to open virtual mailbox maps %s %s\n", config.ConfigInstance().VMailboxMaps, err)
  179. }
  180. defer db.Close()
  181. err = db.Put(email, emailParts[1]+"/"+emailParts[0])
  182. if err != nil {
  183. return errors.New("Unable to add email to maps" + err.Error())
  184. }
  185. _, err = s.emailsCollection.UpdateOne(context.Background(),
  186. bson.M{"user": user},
  187. bson.M{"$addToSet": bson.M{"email": email}},
  188. options.Update().SetUpsert(upsert))
  189. return err
  190. }
  191. func (s *Storage) RemoveEmail(user string, email string) error {
  192. log.Printf("User %s removes email %s", user, email)
  193. result := s.emailsCollection.FindOne(context.Background(), bson.M{
  194. "user": user,
  195. "email": email,
  196. })
  197. if result.Err() != nil {
  198. return result.Err()
  199. }
  200. db, err := berkeleydb.NewDB()
  201. if err != nil {
  202. log.Fatal(err)
  203. }
  204. err = db.Open(config.ConfigInstance().VMailboxMaps, berkeleydb.DbHash, 0)
  205. if err != nil {
  206. log.Fatalf("Unable to open virtual mailbox maps %s %s\n", config.ConfigInstance().VMailboxMaps, err)
  207. }
  208. defer db.Close()
  209. err = db.Delete(email)
  210. if err != nil {
  211. return errors.New("Unable to remove email from maps" + err.Error())
  212. }
  213. err = s.cleanupAttachments(user, email)
  214. if err != nil {
  215. log.Printf("Unable to cleanup attachments for %s %s\n", email, err)
  216. }
  217. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  218. mailsCollection.DeleteMany(context.Background(), bson.M{"email": email})
  219. _, err = s.emailsCollection.UpdateOne(context.Background(),
  220. bson.M{"user": user},
  221. bson.M{"$pull": bson.M{"email": email}})
  222. return err
  223. }
  224. func (s *Storage) SaveMail(email, folder string, m *common.Mail, read bool) error {
  225. user := &struct {
  226. User string
  227. }{}
  228. s.emailsCollection.FindOne(context.Background(), bson.M{"email": email}).Decode(user)
  229. mailsCollection := s.db.Collection(qualifiedMailCollection(user.User))
  230. result, err := mailsCollection.InsertOne(context.Background(), &struct {
  231. Email string
  232. Mail *common.Mail
  233. Folder string
  234. Read bool
  235. Trash bool
  236. }{
  237. Email: email,
  238. Mail: m,
  239. Folder: folder,
  240. Read: read,
  241. Trash: false,
  242. }, options.InsertOne().SetBypassDocumentValidation(true))
  243. if err != nil {
  244. return err
  245. }
  246. mail := *m //deep copy for multithreading
  247. s.notifyNewMail(email, common.MailMetadata{
  248. Id: result.InsertedID.(primitive.ObjectID).Hex(),
  249. Read: false,
  250. Trash: false,
  251. Folder: folder,
  252. User: user.User,
  253. Mail: &mail,
  254. })
  255. return nil
  256. }
  257. func (s *Storage) MoveMail(user string, mailId string, folder string) error {
  258. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  259. oId, err := primitive.ObjectIDFromHex(mailId)
  260. if err != nil {
  261. return err
  262. }
  263. if folder == common.Trash {
  264. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": bson.M{"trash": true}})
  265. } else {
  266. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": bson.M{"folder": folder, "trash": false}})
  267. }
  268. return err
  269. }
  270. func (s *Storage) RestoreMail(user string, mailId string) error {
  271. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  272. oId, err := primitive.ObjectIDFromHex(mailId)
  273. if err != nil {
  274. return err
  275. }
  276. //TODO: Legacy for old databases remove soon
  277. metadata, err := s.GetMail(user, mailId)
  278. if metadata.Folder == common.Trash {
  279. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": bson.M{"folder": common.Inbox}})
  280. }
  281. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": bson.M{"trash": false}})
  282. return err
  283. }
  284. func (s *Storage) DeleteMail(user string, mailId string) error {
  285. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  286. oId, err := primitive.ObjectIDFromHex(mailId)
  287. if err != nil {
  288. return err
  289. }
  290. var result common.MailMetadata
  291. err = mailsCollection.FindOne(context.Background(), bson.M{"_id": oId}).Decode(&result)
  292. if err != nil {
  293. return err
  294. }
  295. for _, attachment := range result.Mail.Body.Attachments {
  296. removeAttachment(attachment.Id)
  297. }
  298. _, err = mailsCollection.DeleteOne(context.Background(), bson.M{"_id": oId})
  299. return err
  300. }
  301. func (s *Storage) GetMailList(user, email, folder string, frame common.Frame) ([]*common.MailMetadata, error) {
  302. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  303. matchFilter := bson.M{"email": email}
  304. if folder == common.Trash {
  305. matchFilter["$or"] = bson.A{
  306. bson.M{"trash": true},
  307. bson.M{"folder": folder}, //TODO: Legacy for old databases remove soon
  308. }
  309. } else {
  310. matchFilter["folder"] = folder
  311. matchFilter["$or"] = bson.A{
  312. bson.M{"trash": false},
  313. bson.M{"trash": bson.M{"$exists": false}}, //TODO: Legacy for old databases remove soon
  314. }
  315. }
  316. request := bson.A{
  317. bson.M{"$match": matchFilter},
  318. bson.M{"$sort": bson.M{"mail.header.date": -1}},
  319. }
  320. if frame.Skip > 0 {
  321. request = append(request, bson.M{"$skip": frame.Skip})
  322. }
  323. fmt.Printf("Trying limit number of mails: %v\n", frame)
  324. if frame.Limit > 0 {
  325. fmt.Printf("Limit number of mails: %v\n", frame)
  326. request = append(request, bson.M{"$limit": frame.Limit})
  327. }
  328. cur, err := mailsCollection.Aggregate(context.Background(), request)
  329. if err != nil {
  330. log.Println(err.Error())
  331. return nil, err
  332. }
  333. var headers []*common.MailMetadata
  334. for cur.Next(context.Background()) {
  335. result := &common.MailMetadata{}
  336. err = cur.Decode(result)
  337. if err != nil {
  338. log.Printf("Unable to read database mail record: %s", err)
  339. continue
  340. }
  341. // fmt.Printf("Add mail: %s", result.Id)
  342. headers = append(headers, result)
  343. }
  344. // fmt.Printf("Mails read from database: %v", headers)
  345. return headers, nil
  346. }
  347. func (s *Storage) GetUserInfo(user string) (*common.UserInfo, error) {
  348. result := &common.UserInfo{}
  349. err := s.usersCollection.FindOne(context.Background(), bson.M{"user": user}).Decode(result)
  350. return result, err
  351. }
  352. func (s *Storage) GetEmailStats(user string, email string, folder string) (unread, total int, err error) {
  353. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  354. result := &struct {
  355. Total int
  356. Unread int
  357. }{}
  358. matchFilter := bson.M{"email": email}
  359. if folder == common.Trash {
  360. matchFilter["$or"] = bson.A{
  361. bson.M{"trash": true},
  362. bson.M{"folder": folder}, //TODO: Legacy for old databases remove soon
  363. }
  364. } else {
  365. matchFilter["folder"] = folder
  366. matchFilter["$or"] = bson.A{
  367. bson.M{"trash": false},
  368. bson.M{"trash": bson.M{"$exists": false}}, //TODO: Legacy for old databases remove soon
  369. }
  370. }
  371. unreadMatchFilter := matchFilter
  372. unreadMatchFilter["read"] = false
  373. cur, err := mailsCollection.Aggregate(context.Background(), bson.A{bson.M{"$match": unreadMatchFilter}, bson.M{"$count": "unread"}})
  374. if err == nil && cur.Next(context.Background()) {
  375. cur.Decode(result)
  376. } else {
  377. return 0, 0, err
  378. }
  379. cur, err = mailsCollection.Aggregate(context.Background(), bson.A{bson.M{"$match": matchFilter}, bson.M{"$count": "total"}})
  380. if err == nil && cur.Next(context.Background()) {
  381. cur.Decode(result)
  382. } else {
  383. return 0, 0, err
  384. }
  385. return result.Unread, result.Total, err
  386. }
  387. func (s *Storage) GetMail(user string, id string) (metadata *common.MailMetadata, err error) {
  388. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  389. oId, err := primitive.ObjectIDFromHex(id)
  390. if err != nil {
  391. return nil, err
  392. }
  393. metadata = &common.MailMetadata{
  394. Mail: common.NewMail(),
  395. }
  396. err = mailsCollection.FindOne(context.Background(), bson.M{"_id": oId}).Decode(metadata)
  397. if err != nil {
  398. return nil, err
  399. }
  400. return metadata, nil
  401. }
  402. func (s *Storage) SetRead(user string, id string, read bool) error {
  403. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  404. oId, err := primitive.ObjectIDFromHex(id)
  405. if err != nil {
  406. return err
  407. }
  408. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": bson.M{"read": read}})
  409. return err
  410. }
  411. func (s *Storage) UpdateMail(user string, id string, mailMap interface{}) error {
  412. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  413. oId, err := primitive.ObjectIDFromHex(id)
  414. if err != nil {
  415. return err
  416. }
  417. _, err = mailsCollection.UpdateOne(context.Background(), bson.M{"_id": oId}, bson.M{"$set": mailMap})
  418. return err
  419. }
  420. func (s *Storage) GetUsers() (users []string, err error) {
  421. return nil, nil
  422. }
  423. func (s *Storage) GetEmails(user string) (emails []string, err error) {
  424. result := &struct {
  425. Email []string
  426. }{}
  427. err = s.emailsCollection.FindOne(context.Background(), bson.M{"user": user}).Decode(result)
  428. if err != nil {
  429. return nil, err
  430. }
  431. return result.Email, nil
  432. }
  433. func (s *Storage) GetAllEmails() (emails []string, err error) {
  434. cur, err := s.allEmailsCollection.Find(context.Background(), bson.M{})
  435. if cur.Next(context.Background()) {
  436. result := struct {
  437. Emails []string
  438. }{}
  439. err = cur.Decode(&result)
  440. if err == nil {
  441. return result.Emails, nil
  442. }
  443. }
  444. return nil, err
  445. }
  446. func (s *Storage) CheckEmailExists(email string) bool {
  447. result := s.allEmailsCollection.FindOne(context.Background(), bson.M{"emails": email})
  448. return result.Err() == nil
  449. }
  450. func (s *Storage) GetFolders(email string) (folders []*common.Folder) {
  451. folders = []*common.Folder{
  452. &common.Folder{Name: common.Inbox, Custom: false},
  453. &common.Folder{Name: common.Sent, Custom: false},
  454. &common.Folder{Name: common.Trash, Custom: false},
  455. &common.Folder{Name: common.Spam, Custom: false},
  456. }
  457. return
  458. }
  459. func (s *Storage) ReadEmailMaps() (map[string]string, error) {
  460. registredEmails, err := s.GetAllEmails()
  461. if err != nil {
  462. return nil, err
  463. }
  464. mailPath := config.ConfigInstance().VMailboxBase
  465. mapsFile := config.ConfigInstance().VMailboxMaps
  466. if !utils.FileExists(mapsFile) {
  467. return nil, errors.New("Could not read virtual mailbox maps")
  468. }
  469. db, err := berkeleydb.NewDB()
  470. if err != nil {
  471. log.Fatal(err)
  472. }
  473. err = db.Open(config.ConfigInstance().VMailboxMaps, berkeleydb.DbHash, berkeleydb.DbRdOnly)
  474. if err != nil {
  475. return nil, errors.New("Unable to open virtual mailbox maps " + mapsFile + " " + err.Error())
  476. }
  477. defer db.Close()
  478. cursor, err := db.Cursor()
  479. if err != nil {
  480. return nil, errors.New("Unable to read virtual mailbox maps " + mapsFile + " " + err.Error())
  481. }
  482. emailMaps := make(map[string]string)
  483. for true {
  484. email, path, dberr := cursor.GetNext()
  485. if dberr != nil {
  486. break
  487. }
  488. found := false
  489. for _, registredEmail := range registredEmails {
  490. if email == registredEmail {
  491. found = true
  492. }
  493. }
  494. if !found {
  495. return nil, errors.New("Found non-registred mailbox <" + email + "> in mail maps. Database has inconsistancy")
  496. }
  497. emailMaps[email] = mailPath + "/" + path
  498. }
  499. for _, registredEmail := range registredEmails {
  500. if _, exists := emailMaps[registredEmail]; !exists {
  501. return nil, errors.New("Found existing mailbox <" + registredEmail + "> in database. Mail maps has inconsistancy")
  502. }
  503. }
  504. return emailMaps, nil
  505. }
  506. func removeAttachment(attachmentId string) error {
  507. attachmentPath := config.ConfigInstance().AttachmentsPath + "/" + attachmentId
  508. err := os.Remove(attachmentPath)
  509. if err != nil {
  510. log.Printf("Unable to remove attachment file: %s. Database inconsistency", attachmentPath)
  511. }
  512. return err
  513. }
  514. func (s *Storage) cleanupAttachments(user, email string) error {
  515. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  516. cur, err := mailsCollection.Aggregate(context.Background(), bson.A{
  517. bson.M{"$match": bson.M{"email": email}},
  518. bson.M{"$project": bson.M{"mail.body.attachments": 1}},
  519. bson.M{"$unwind": "$mail.body.attachments"},
  520. bson.M{"$replaceRoot": bson.M{"newRoot": "$mail.body.attachments"}},
  521. })
  522. if err != nil {
  523. return err
  524. }
  525. for cur.Next(context.Background()) {
  526. var attachment common.AttachmentHeader
  527. err = cur.Decode(&attachment)
  528. if err != nil {
  529. log.Printf("Unable to decode attachment")
  530. }
  531. removeAttachment(attachment.Id)
  532. }
  533. return nil
  534. }
  535. func (s *Storage) CheckAttachment(user, attachment string) bool {
  536. mailsCollection := s.db.Collection(qualifiedMailCollection(user))
  537. result := mailsCollection.FindOne(context.Background(), bson.M{"mail.body.attachments.id": attachment})
  538. return result.Err() == nil
  539. }
  540. func (s *Storage) RegisterNotifier(notifier common.Notifier) {
  541. if notifier != nil {
  542. notifiers.notifiersLock.Lock()
  543. defer notifiers.notifiersLock.Unlock()
  544. notifiers.notifiers = append(notifiers.notifiers, notifier)
  545. }
  546. }
  547. func (s *Storage) notifyNewMail(email string, mail common.MailMetadata) {
  548. notifiers.notifiersLock.Lock()
  549. defer notifiers.notifiersLock.Unlock()
  550. for _, notifier := range notifiers.notifiers {
  551. notifier.NotifyNewMail(email, mail)
  552. }
  553. }
  554. func (s *Storage) notifyMailboxUpdate(email string) {
  555. notifiers.notifiersLock.Lock()
  556. defer notifiers.notifiersLock.Unlock()
  557. for _, notifier := range notifiers.notifiers {
  558. notifier.NotifyMaiboxUpdate(email)
  559. }
  560. }