'Return the message\'s header text as a string.  If an
argument is specified, it is used as a filter predicate to
decide which headers to return (its argument is the header
name converted to lower case).'

def getheadertext(self, pred=None):

    if (pred is None):
        return ''.join(self.headers)
    headers = []
    hit = 0
    for line in self.headers:
        if (not line[0].isspace()):
            i = line.find(':')
            if (i > 0):
                hit = pred(line[:i].lower())
        if hit:
            headers.append(line)
    return ''.join(headers)
