Changeset 911e2f3298d2f980ed158a446da3bf09b96dd8bb
- Timestamp:
- 08/10/06 08:41:29
(2 years ago)
- Author:
- pj <pj@03e2507f-5f03-0410-b1bc-a06d56394c08>
- git-committer:
- pj <pj@03e2507f-5f03-0410-b1bc-a06d56394c08> 1155217289 +0000
- git-parent:
[d8ed33905b8d5230e6852118093024308effbbca]
- git-author:
- pj <pj@03e2507f-5f03-0410-b1bc-a06d56394c08> 1155217289 +0000
- Message:
* switch from readlisp to sexpr
* fix pick behaviour to return 0 instead of (so that scan pick foo never
gets you all of the records)
git-svn-id: file:///home/pj/.svnroot/mhi@37 03e2507f-5f03-0410-b1bc-a06d56394c08
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r8bcd848 |
r911e2f3 |
|
| 19 | 19 | import sys |
|---|
| 20 | 20 | import time |
|---|
| | 21 | import sexpr |
|---|
| 21 | 22 | import string |
|---|
| 22 | 23 | import imaplib |
|---|
| | 24 | import StringIO |
|---|
| 23 | 25 | from configobj import ConfigObj |
|---|
| 24 | | from readlisp import readlisp |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | cfgdir=os.environ.get('HOME','') |
|---|
| … | … | |
| 32 | 33 | if Debug > 0: |
|---|
| 33 | 34 | print "DEBUG: %s" % dstr |
|---|
| | 35 | |
|---|
| | 36 | def readsexpr(s): |
|---|
| | 37 | return sexpr.SexprParser(StringIO.StringIO(s)).parse() |
|---|
| 34 | 38 | |
|---|
| 35 | 39 | |
|---|
| … | … | |
| 216 | 220 | sys.exit(1) |
|---|
| 217 | 221 | |
|---|
| | 222 | def do_or_die(func, errormsg): |
|---|
| | 223 | result, data = func |
|---|
| | 224 | if result != 'OK': |
|---|
| | 225 | print msgstr+' %s' % data |
|---|
| | 226 | sys.exit(1) |
|---|
| | 227 | return result, data |
|---|
| | 228 | |
|---|
| 218 | 229 | def _fixupMsgset(msgset, last): |
|---|
| 219 | 230 | # s/cur/$cur/, s/last/$last/, s/prev/$prev/, s/next/$next/ |
|---|
| | 231 | msgset = msgset.replace('-', ':') |
|---|
| 220 | 232 | cur= state[state['folder']+'.cur'] |
|---|
| 221 | 233 | msgset = msgset.replace('cur', cur) |
|---|
| 222 | 234 | msgset = msgset.replace('last', last) |
|---|
| | 235 | msgset = msgset.replace('$', last) |
|---|
| 223 | 236 | # XXX: bounds-check these? |
|---|
| 224 | 237 | msgset = msgset.replace('next', str(int(cur)+1)) |
|---|
| … | … | |
| 229 | 242 | def _checkMsgset(msgset): |
|---|
| 230 | 243 | ## FIXME: need a better check that msgset is a valid imap messageset string |
|---|
| 231 | | # msgset = int | int:int | int,msgset |
|---|
| | 244 | # msgset = int | int:int | msgset,msgset |
|---|
| 232 | 245 | # '1', '1:5', '1,2,3', '1,3:5' are all valid |
|---|
| 233 | 246 | if len(msgset.strip('1234567890,:*')) != 0: |
|---|
| … | … | |
| 347 | 360 | stats = {} |
|---|
| 348 | 361 | for fline in flist: |
|---|
| 349 | | f = str(readlisp('('+fline+')')[2]) |
|---|
| | 362 | f = str(readsexpr('('+fline+')')[2]) |
|---|
| 350 | 363 | _debug(" f: %s " % repr(f)) |
|---|
| 351 | | stats[f] = readlisp('('+S.status(f, '(MESSAGES RECENT UNSEEN)')[1][0]+')')[1] |
|---|
| | 364 | stats[f] = readsexpr('('+S.status(f, '(MESSAGES RECENT UNSEEN)')[1][0]+')')[1] |
|---|
| 352 | 365 | S.logout() |
|---|
| 353 | 366 | stats["FOLDER"] = [0, "# MESSAGES", 0, "RECENT", 0, "UNSEEN"] |
|---|
| … | … | |
| 361 | 374 | foo = stats[folder] |
|---|
| 362 | 375 | _debug(" Stats: %s " % repr(foo)) |
|---|
| 363 | | #_debug("Statsrl: %s " % repr(readlisp(foo))) |
|---|
| | 376 | #_debug("Statsrl: %s " % repr(readsexpr(foo))) |
|---|
| 364 | 377 | messages, recent, unseen = foo[1], foo[3], foo[5] |
|---|
| 365 | 378 | cur = state.get(folder+'.cur', None) |
|---|
| … | … | |
| 391 | 404 | result, data = S.search(None, searchstr) |
|---|
| 392 | 405 | _check_result(result, data, "Problem with search criteria:") |
|---|
| | 406 | _debug("data: %s" % repr(data)) |
|---|
| 393 | 407 | S.close() |
|---|
| 394 | 408 | S.logout() |
|---|
| 395 | | msglist = [] |
|---|
| 396 | | for m in data: |
|---|
| 397 | | msglist += m.split() |
|---|
| 398 | | print ','.join(msglist) |
|---|
| | 409 | data = [d for d in data if d != ''] |
|---|
| | 410 | if data: |
|---|
| | 411 | msglist = [] |
|---|
| | 412 | for m in data: |
|---|
| | 413 | msglist += m.split() |
|---|
| | 414 | print ','.join(msglist) |
|---|
| | 415 | else: |
|---|
| | 416 | print "0" |
|---|
| 399 | 417 | |
|---|
| 400 | 418 | |
|---|
| … | … | |
| 412 | 430 | if not msgset: |
|---|
| 413 | 431 | try: |
|---|
| 414 | | msgset = state[folder+".cur"] |
|---|
| | 432 | msgset = state[state["folder"]+".cur"] |
|---|
| 415 | 433 | except KeyError: |
|---|
| 416 | 434 | print "No current message selected." |
|---|
| … | … | |
| 578 | 596 | result, data = S.select(folder) |
|---|
| 579 | 597 | _check_result(result, data, "Problem changing to folder:" ) |
|---|
| 580 | | result, data = S.fetch(msgset, '(ENVELOPE FLAGS)') |
|---|
| | 598 | try: |
|---|
| | 599 | result, data = S.fetch(msgset, '(ENVELOPE FLAGS)') |
|---|
| | 600 | except: pass |
|---|
| 581 | 601 | _debug('result: %s' % repr(result)) |
|---|
| 582 | 602 | _debug('data: %s' % repr(data)) |
|---|
| 583 | 603 | _check_result(result, data, "Problem with fetch:" ) |
|---|
| 584 | | if data[0] is None: |
|---|
| | 604 | # take out fake/ba hits |
|---|
| | 605 | data = [ hit for hit in data if ' ' in hit ] |
|---|
| | 606 | if data == [] or data[0] is None: |
|---|
| 585 | 607 | print "No messages." |
|---|
| 586 | 608 | sys.exit(0) |
|---|
| … | … | |
| 594 | 616 | num = string.atoi(num) |
|---|
| 595 | 617 | _debug("e: %s" % repr(e)) |
|---|
| 596 | | e = readlisp(e) |
|---|
| | 618 | e = readsexpr(e) |
|---|
| 597 | 619 | env_date, env_subject, env_from, env_sender = e[1][:4] |
|---|
| 598 | 620 | flags = [str(f) for f in e[3]] |
|---|
| … | … | |
| 668 | 690 | if cmdfunc: |
|---|
| 669 | 691 | _debug("cmdfunc: %s" % cmdfunc) |
|---|
| 670 | | cmdfunc(cmdargs) |
|---|
| | 692 | try: |
|---|
| | 693 | cmdfunc(cmdargs) |
|---|
| | 694 | except IOError: pass |
|---|
| 671 | 695 | config.write() |
|---|
| 672 | 696 | state.write() |
|---|