Skip to content

Commit

Permalink
Merge pull request #1917 from justin2004/enable-imap
Browse files Browse the repository at this point in the history
enable imap
  • Loading branch information
anjakefala committed Jun 14, 2023
2 parents 4dcfee2 + a94835b commit 68c14e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ eleventyNavigation:
|xls |Excel spreadsheets |0\.42 | |0\.42 |1987 |Microsoft |xlrd |
|[fixed](#fixed)|fixed width text |0\.97 | |0\.97 | | | |
|[postgres](#postgres)|PostgreSQL database |0\.97 | |0\.97 |1996 | | |
|[imap](#imap)|Internet Message Access Protocol |2\.12 | |2\.12 |1988 | | |
|[vd](#vd) |VisiData command log|0\.97 | |0\.97 |2017 |VisiData | |
|vds | |VisiData Sheet |2\.2 |yes |2021 |VisiData | | |
|[mbtiles](#mbtiles)|MapBox Tileset |0\.98 | |0\.98 |2011 |MapBox |mapbox\-vector\-tile|
Expand Down Expand Up @@ -102,6 +103,10 @@ eleventyNavigation:
- `postgres_schema` (default: 'public') the desired schema for the Postgres database
- `vd postgres://`*username*`:`*password*`@`*hostname*`:`*port*`/`*database* opens a connection to the given postgres database.

## imap {#imap}
- `vd "imap://[email protected]:[email protected]"` opens a connection to the IMAP server
- e.g. `vd "imap://[email protected]:[email protected]:993"`

### using VisiData as a pager within psql

In psql:
Expand Down
13 changes: 7 additions & 6 deletions visidata/loaders/imap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from visidata import vd, TableSheet, asyncthread, ColumnItem, Column, ColumnAttr, Progress
from visidata import VisiData, vd, TableSheet, asyncthread, ColumnItem, Column, ColumnAttr, Progress
from urllib.parse import urlparse


def openurl_imap(p, **kwargs):
url = urlparse(p.given)
password = url.password or vd.error('no password given in url') # vd.input("imap password for %s" % user, display=False))
return ImapSheet(url.hostname, source=url, password=password)
@VisiData.api
def openurl_imap(vd, url, **kwargs):
url_parsed = urlparse(str(url))
password = url_parsed.password or vd.error('no password given in url') # vd.input("imap password for %s" % user, display=False))
return ImapSheet(url_parsed.hostname, source=url_parsed, password=password)


class ImapSheet(TableSheet):
Expand All @@ -32,7 +33,7 @@ def reload(self):
m.login(user, self.password)
typ, folders = m.list()
for r in Progress(folders, gerund="downloading"):
fname = r.decode('utf-8').split()[-1][1:-1]
fname = r.decode('utf-8').split()[-1]
try:
m.select(fname)
typ, data = m.search(None, 'ALL')
Expand Down

0 comments on commit 68c14e9

Please sign in to comment.