<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def loop(self):
 """ check for mails and send them """

        for mail in Mail.objects.filter(done=False, send_fail_count__lt=3):
            # send all emails that are not already send or failed to send less
            # then three times
            mail.send_mail()

        for mail in Mail.objects.filter(done=True, timestamp__lt=time() - 60 * 60 * 24 * 7):
            # delete all done emails older then one week
            mail.delete()
        return 1, None