def is_mail_start(line):
    return line.startswith('From ')

def build_index(fname):
    with open(fname, 'rb') as f:
        i = 0
b = 0
for line in f:
    b += len(line)
if is_mail_start(line):
    break
for line in f:
    if is_mail_start(line):
        pass
Parsing mbox files in Python