def plainkiosk(self): self.kiosktest() itemscopy = self.items[:] # news search is very fast, so always try it first self.newssearch(os.environ.get('NNTPSERVER') or 'localhost') if self.items and not self.ui.news: if not self.ui.local: # try mail2news gateway self.newssearch('news.gmane.org') if self.items: self.getmhiers() if self.ui.mask: self.maskompile() self.mailsearch() if self.items: self.ui.note('%s not in specified local mailboxes\n' % util.plural(len(self.items), 'message')) if not self.ui.local: for nserv in self.ui.configlist('net', 'newsservers'): if self.items: self.newssearch(nserv) if self.items: self.gogoogle() elif self.items: time.sleep(3) if self.msgs: firstid = None for mid in itemscopy: if mid not in self.items: firstid = mid break self.openkiosk(firstid)
def pagemenu(self): '''Lets user page through a list of items and make a choice.''' header = self.coltrunc('*%s*\n' % util.plural(self.ilen, self.name), self.cols - 2) if not self.more: cs = ', ^C:cancel' if self.ckey: cs += ', %s<%s>' % (self.ckey, self.crit) if self.itemsdict: cs += ', number' menu = '[%s]%s ' % (self.qfunc, cs) resp, valid = self.choice(header, menu) if valid: return resp return self.pagemenu() else: # more than 1 page # switch paging command according to paging direction pds = {-1: 'back', 1: 'forward'} pn = 1 # start at first page pdir = -1 # initial paging direction reversed while True: bs = '' # reverse paging direction if self.plen > 1: if 1 < pn < self.plen: bs = '-:%s, ' % pds[pdir*-1] else: pdir *= -1 menu = ('page %d of %d [%s], ^C:cancel, %sq:%s' % (pn, self.plen, pds[pdir], bs, self.qfunc)) else: # items selected by self.crit might fit on 1 page menu = '^C:cancel, q:%s' % self.qfunc if self.ckey: menu += ', %s<%s>' % (self.ckey, self.crit) menu += ', number ' resp, valid = self.choice(header, menu, pn) if valid: return resp if resp == '-' and bs or resp and pn in (1, self.plen): # on first and last page with invalid response # preemptively switch direction pdir *= -1 pn = max(1, min(pn + pdir, self.plen))
def urlsearch(self): self.urlcollect() if not self.files: it = iterm.iterm() it.terminit() if self.items: ulist = '\n'.join(self.items) uspec = util.plural(len(self.items), ('url', 'message-id')[self.ui.proto=='mid']) yorn = '%s\nretrieve the above %s? yes, [No] ' % (ulist, uspec) answer = input(yorn).lower() else: msg = 'no %ss found. [ok] ' % ('url', 'message-id')[self.ui.proto=='mid'] input(msg) answer = '' if not self.files: it.reinit() if answer in ('y', 'yes'): self.urlgo()
def urlsearch(self): self.urlcollect() if not self.files: it = iterm.iterm() it.terminit() if self.items: ulist = '\n'.join(self.items) uspec = util.plural(len(self.items), ('url', 'message-id')[self.ui.proto == 'mid']) yorn = '%s\nretrieve the above %s? yes, [No] ' % (ulist, uspec) answer = raw_input(yorn).lower() else: msg = 'no %ss found. [ok] ' % ( 'url', 'message-id')[self.ui.proto == 'mid'] raw_input(msg) answer = '' if not self.files: it.reinit() if answer in ('y', 'yes'): self.urlgo()
def newssearch(self, sname): '''Retrieves messages from newsserver.''' self.ui.note('searching news server %s\n' % sname) try: nserv = nntplib.NNTP(sname, readermode=True, usenetrc=True) except (nntplib.NNTPPermanentError, nntplib.NNTPTemporaryError): try: nserv = nntplib.NNTP(sname, readermode=True, usenetrc=False) except (nntplib.NNTPPermanentError, nntplib.NNTPTemporaryError) as inst: self.ui.warn('%s\n' % inst) return for mid in self.items[:]: try: art = nserv.article('<%s>' % mid) art = '\n'.join(art[-1]) + '\n' self.msgs.append(email.message_from_string(art)) self.items.remove(mid) except nntplib.NNTPTemporaryError: pass nserv.quit() if self.items: self.ui.note('%s not on server %s\n' % (util.plural(len(self.items), 'message'), sname))
except (nntplib.NNTPPermanentError, nntplib.NNTPTemporaryError), inst: self.ui.warn('%s\n' % inst) return for mid in self.items[:]: try: art = nserv.article('<%s>' % mid) art = '\n'.join(art[-1]) + '\n' self.msgs.append(email.message_from_string(art)) self.items.remove(mid) except nntplib.NNTPTemporaryError: pass nserv.quit() if self.items: self.ui.note('%s not on server %s\n' % (util.plural(len(self.items), 'message'), sname)) def boxparser(self, path, maildir=False, isspool=False): if (not isspool and path == self.mspool or self.ui.mask and self.ui.mask.search(path) is not None): return if maildir: try: dl = os.listdir(path) except OSError: return for d in 'cur', 'new', 'tmp': if d not in dl: return mbox = mailbox.Maildir(path, _msgfactory) else: