Advertisement
Guest User

IMAPfilter example

a guest
Mar 9th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. ----------------------------------------------------
  2. -- Create these folders in your mail browser -------
  3. ----------------------------------------------------
  4. --
  5. -- yeah, yeah I know they are stupid names
  6. -- FileterEmail
  7. -- SalesCrap
  8. -- --and any other folder you might need/want
  9. --
  10. ----------------------------------------------------
  11. -- Here is where you will install imapfilter -------
  12. ----------------------------------------------------
  13. --
  14. -- sudo apt-get install imapfilter
  15. --
  16. ----------------------------------------------------
  17. -- You will need to make your config folder --------
  18. ----------------------------------------------------
  19. --
  20. -- mkdir -p ~/.imapfilter
  21. -- cd ~/.imapfilter
  22. --
  23. ----------------------------------------------------
  24. -- Create the config.lua file ----------------------
  25. ----------------------------------------------------
  26. --
  27. -- touch config.lua
  28. -- nano config.lua
  29. --
  30. ----------------------------------------------------
  31. -- Read documentation and examples on Github -------
  32. ----------------------------------------------------
  33. --
  34. -- https://github.com/lefcha/imapfilter/blob/master/samples/config.lua
  35. --
  36. ----------------------------------------------------
  37. -- Edit the cron job so it runs automatically ------
  38. ----------------------------------------------------
  39. -- edit crontab:
  40. -- crontab -e
  41. -- add line:
  42. -- */15 * * * * imapfilter
  43. -- or
  44. -- 0,15,30,45 * * * * imapfilter
  45. ----------------------------------------------------
  46.  
  47. ----------------------------------------------------
  48. -- Options -----------------------------------------
  49. ----------------------------------------------------
  50.  
  51. options.timeout = 45
  52. options.subscribe = true
  53. options.starttls = true
  54.  
  55. ----------------------------------------------------
  56. -- Accounts Setup ----------------------------------
  57. ----------------------------------------------------
  58.  
  59. Email = IMAP {
  60. server = '[YOUR_SERVER]', -- ex. imap.googlemail.com
  61. username = '[YOUR_USERNAME]',
  62. password = '[YOUR_PASSWORD]',
  63. ssl = 'tls1'
  64. }
  65.  
  66. ----------------------------------------------------
  67. -- Filters -----------------------------------------
  68. ----------------------------------------------------
  69. -- I move my unseen email to a temp folder before
  70. -- I filter it, then move it back. This works for
  71. -- me because otherwise I noticed it was scanning
  72. -- all of my email every time. That could have been
  73. -- user error though
  74.  
  75. -- Move new mail to 'FileterEmail'
  76. new_messages = Email.INBOX:is_unseen()
  77. new_messages:move_messages(Email['FileterEmail'])
  78.  
  79. -- Buy Me Now!!!
  80. messages = Email['FileterEmail']:contain_subject('Sales just for you! do not miss them!') +
  81. Email['FileterEmail']:contain_subject('[100tb.com] Invoice Notice')
  82. Email['FileterEmail']:mark_seen(messages)
  83. messages:move_messages(Email['SalesCrap'])
  84.  
  85. -- Place all email back in INBOX
  86. remaining = Email['FileterEmail']:select_all()
  87. remaining:move_messages(Email.INBOX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement