#!/usr/bin/env python
# encoding: UTF-8

"""
    User sends notes, tweets, whatever, to his notes box

    Daily, this script fetches all received mail in this notes box,
    and builds a single HTML document listing all mails/notes,
    and mails it back to the user main mailbox.

    Goal: have a readable, single document, summarizing all daily notes.

    2012, rda, WTFPL-2
"""

import sys
sys.path.append('./conf')
sys.path.append('./lib')

from reply_email import *
from reminder_email import get_report_time_scope
from mails import imap_conf

year, week = get_report_time_scope()

replies = fetch_replies(imap_conf)
replies = map(extract_mail_body, replies)

print json.dumps(replies, sort_keys=True, indent=2)

# s = open('reply.txt', 'r').read()
# report = parse_mail_body(s)
# 
# print json.dumps(report, sort_keys=True, indent=4)
# print "\n".join(report["done"])

report = build_report(replies, year, week)

print report 
# TODO(rda) post report to wiki, to new page "Rapport_hebdo_semaine_%d_%d" % (year, week)

#FILE = open("report/index.html", "w")
#FILE.writelines(html)
#FILE.close()
