2023-11-14 18:12:26 +08:00
|
|
|
import os
|
|
|
|
|
import logging
|
|
|
|
|
import json
|
|
|
|
|
import string
|
2023-11-30 21:04:19 -08:00
|
|
|
from aios import *
|
2023-11-14 18:12:26 +08:00
|
|
|
from .mail import Mail, MailStorage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LocalEmail:
|
|
|
|
|
def __init__(self, env: KnowledgePipelineEnvironment, config:dict):
|
|
|
|
|
self.config = config
|
|
|
|
|
self.env = env
|
|
|
|
|
path = string.Template(config["path"]).substitute(myai_dir=AIStorage.get_instance().get_myai_dir())
|
|
|
|
|
self.mail_storage = MailStorage(path, config.get("watch"))
|
|
|
|
|
|
|
|
|
|
async def next(self):
|
|
|
|
|
while True:
|
|
|
|
|
parsed = None
|
|
|
|
|
journals = self.env.journal.latest_journals(1)
|
|
|
|
|
if len(journals) == 1:
|
|
|
|
|
latest_journal = journals[0]
|
|
|
|
|
if latest_journal.is_finish():
|
|
|
|
|
yield None
|
|
|
|
|
continue
|
2023-12-01 14:29:10 +08:00
|
|
|
parsed = latest_journal.get_input()
|
2023-11-14 18:12:26 +08:00
|
|
|
|
|
|
|
|
mail_id = self.mail_storage.next_mail_id(parsed)
|
|
|
|
|
if mail_id is None:
|
|
|
|
|
yield (None, None)
|
|
|
|
|
else:
|
|
|
|
|
yield (mail_id, str(mail_id))
|
|
|
|
|
|
2023-11-20 22:01:18 +08:00
|
|
|
|
|
|
|
|
class LocalEmailWithFilter:
|
|
|
|
|
def __init__(self, env: KnowledgePipelineEnvironment, config:dict):
|
|
|
|
|
pass
|