{"id":13858712,"url":"https://github.com/infertux/imap_guard","last_synced_at":"2025-04-13T16:09:29.936Z","repository":{"id":7533250,"uuid":"8885058","full_name":"infertux/imap_guard","owner":"infertux","description":"RubyGem to manage emails on IMAP servers","archived":false,"fork":false,"pushed_at":"2025-03-01T03:07:15.000Z","size":68,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T07:01:45.846Z","etag":null,"topics":["antispam","email","imap","mailbox","ruby","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infertux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-19T17:47:36.000Z","updated_at":"2025-03-01T03:07:18.000Z","dependencies_parsed_at":"2024-03-06T01:45:07.390Z","dependency_job_id":null,"html_url":"https://github.com/infertux/imap_guard","commit_stats":{"total_commits":83,"total_committers":1,"mean_commits":83.0,"dds":0.0,"last_synced_commit":"29d1c80cb4acb7f766123a427f3afae28e674fbf"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infertux%2Fimap_guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infertux%2Fimap_guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infertux%2Fimap_guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infertux%2Fimap_guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infertux","download_url":"https://codeload.github.com/infertux/imap_guard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248664544,"owners_count":21141979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antispam","email","imap","mailbox","ruby","rubygem"],"created_at":"2024-08-05T03:02:18.409Z","updated_at":"2025-04-13T16:09:29.915Z","avatar_url":"https://github.com/infertux.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# ImapGuard\n\n[![Gem Version](https://badge.fury.io/rb/imap_guard.svg)](https://badge.fury.io/rb/imap_guard)\n[![Build Status](https://gitlab.com/infertux/imap_guard/badges/master/pipeline.svg)](https://gitlab.com/infertux/imap_guard/-/pipelines)\n[![Code Climate](https://codeclimate.com/github/infertux/imap_guard.png)](https://codeclimate.com/github/infertux/imap_guard)\n[![Inline docs](http://inch-ci.org/github/infertux/imap_guard.svg)](http://inch-ci.org/github/infertux/imap_guard)\n\n**A guard for your IMAP mailboxes.**\n\nImapGuard connects to your IMAP server and processes your emails.\nYou can finely pick them thanks to advanced search queries and Ruby blocks.\nThen you can `move` or `delete` them in batch.\n\nOf course, there is a _dry-run_ mode (i.e. read-only) available to double check what it would do.\n\nIt can be used by a disposable script to clean things up or with a cron job to keep them tidy.\n\n## Installation\n\n    $ gem install imap_guard\n\n## Usage\n\nRead below for detailed explanations.\nIf you prefer a quick overview, you can take a look at [this example](https://github.com/infertux/imap_guard/blob/master/examples/example.rb).\n\nExample initialization:\n\n```ruby\nrequire 'imap_guard'\n\nSETTINGS = {\n  host: 'mail.google.com',\n  port: 993,\n  username: 'login',\n  password: 'pass',\n  read_only: true # don't perform any modification aka dry-run mode\n}\n\nguard = ImapGuard::Guard.new SETTINGS\nguard.login # authenticate the user\nguard.select 'INBOX.ops' # select the mailbox\n```\n\nIMAP search query syntax can be a bit tricky.\n`ImapGuard::Query` can help you to build queries with a simple Ruby DSL:\n\n```ruby\nbase_query = ImapGuard::Query.new.unflagged.unanswered.seen.freeze\nquery = base_query.dup.before(7).subject(\"abc\").from(\"root\")\np query #=\u003e [\"UNFLAGGED\", \"UNANSWERED\", \"SEEN\", \"BEFORE\", \"13-Mar-2013\", \"SUBJECT\", \"abc\", \"FROM\", \"root\"]\nguard.delete query # will delete every emails which match this query\n```\n\nUnfortunately, IMAP search queries are limited too.\nFor instance, the pattern passed to `subject` and `from` is a mere string.\nIMAP doesn't allow advanced filtering such as regexp matching.\n\nTo do so, you can pass an optional block to `delete`.\nThe yielded object is a [Mail] instance of the current mail providing many methods.\nHowever, wrapping the mail into a nice `Mail` object is slow and you should avoid to use it if you can.\n\n```ruby\nguard.delete base_query.dup.before(7).subject(\"Logwatch for \") do |mail|\n  mail.subject =~ /\\ALogwatch for \\w \\(Linux\\)\\Z/ and \\\n  mail.multipart? and \\\n  mail.parts.length == 2\nend\n```\n\nYou can always forge your own raw IMAP search queries (the [RFC](http://tools.ietf.org/html/rfc3501#section-6.4.4) can help in that case):\n\n```ruby\nquery = 'SEEN SUBJECT \"ALERT\" FROM \"root\"'\nguard.delete query do |mail|\n  mail.body == \"ALERT\"\nend\n```\n\nThere is a `move` method as well:\n\n```ruby\nguard.move query, 'destination_folder' do |mail|\n  # and it can take a filter block like `delete`\nend\n```\n\nFinally, this should be handled automatically but you can explicitly expunge pending emails and close the connection:\n\n```ruby\nguard.expunge # effectively delete emails marked as deleted\nguard.close # expunge then close the connection\n```\n\n### Advanced features\n\n#### Mailbox list\n\nYou can list all mailboxes:\n\n```ruby\np guard.list\n```\n\n#### Selected mailbox\n\nYou can output the currently selected mailbox:\n\n```ruby\np guard.mailbox # nil if none has been selected\n```\n\n#### Debug block\n\nYou can pass a block which will be yielded for each matched email:\n\n```ruby\n# Print out the subject for each email\nguard.debug = -\u003e(mail) { print \"#{mail.subject}: \" }\n```\n\nYou can think of it as Ruby's [Object#tap](http://ruby-doc.org/core-2.0/Object.html#method-i-tap) method.\nNote this is slow since it needs to fetch the whole email to return a [Mail] object.\n\n## Contributing\n\nBug reports and patches are most welcome.\n\n## License\n\nMIT\n\n\n[Mail]: https://github.com/mikel/mail\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfertux%2Fimap_guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfertux%2Fimap_guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfertux%2Fimap_guard/lists"}