Skip to content

Commit

Permalink
Fixup to make KB and GB units work in addition to just K and G.
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Dec 28, 2013
1 parent 1e42c28 commit a1bbfc5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mailpile/plugins/sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ def meta_kw_extractor(index, msg_mid, msg, msg_size, msg_ts):

_range_keywords = [
'..',
'-',
'to'
'-'
]
def _mk_logsize(size, default_unit = 0):
def _mk_logsize(size, default_unit=0):
if not size:
return 0
unit = 0
size = size.lower()
if size[-1].isdigit(): # ends with a number
if size[-1].isdigit(): # ends with a number
unit = default_unit
elif len(size) >= 2 and size[-2] in _size_units and size[-1] == 'b':
unit = _size_units[size[-2]]
size = size[:-2]
elif size[-1] in _size_units:
unit = _size_units[size[-1]]
size = size[:-1]
Expand All @@ -57,8 +61,8 @@ def search(config, idx, term, hits):
break
else:
start = end = word
# if no unit is setup in the start term, use the size from the end term

# if no unit is setup in the start term, use the unit from the end term
end_unit_size = end.lower()[-1]
end_unit = 0
if end_unit_size in _size_units:
Expand Down

0 comments on commit a1bbfc5

Please sign in to comment.