<s> from . import base <EOL> import six <EOL> import os . path <EOL> import mailbox <EOL> class Maildir ( base . ThreadedPollText ) : <EOL> """<STR_LIT>""" <EOL> orientations = base . ORIENTATION_HORIZONTAL <EOL> defaults = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , [ ] , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ) , <EOL> ] <EOL> def __init__ ( self , ** config ) : <EOL> base . ThreadedPollText . __init__ ( self , ** config ) <EOL> self . add_defaults ( Maildir . defaults ) <EOL> if isinstance ( self . subFolders [ <NUM_LIT:0> ] , six . string_types ) : <EOL> self . subFolders = [ <EOL> { "<STR_LIT:path>" : folder , "<STR_LIT:label>" : folder } <EOL> for folder in self . subFolders <EOL> ] <EOL> def poll ( self ) : <EOL> """<STR_LIT>""" <EOL> state = { } <EOL> def to_maildir_fmt ( paths ) : <EOL> for path in iter ( paths ) : <EOL> yield path . rsplit ( "<STR_LIT::>" ) [ <NUM_LIT:0> ] <EOL> for subFolder in self . subFolders : <EOL> path = os . path . join ( self . maildirPath , subFolder [ "<STR_LIT:path>" ] ) <EOL> maildir = mailbox . Maildir ( path ) <EOL> state [ subFolder [ "<STR_LIT:label>" ] ] = <NUM_LIT:0> <EOL> for file in to_maildir_fmt ( os . listdir ( os . path . join ( path , "<STR_LIT>" ) ) ) : <EOL> if file in maildir : <EOL> state [ subFolder [ "<STR_LIT:label>" ] ] += <NUM_LIT:1> <EOL> return self . format_text ( state ) <EOL> def format_text ( self , state ) : <EOL> """<STR_LIT>""" <EOL> return self . separator . join ( <EOL> "<STR_LIT>" . format ( * item ) for item in state . items ( ) <EOL> ) </s>
