diff --git a/scraibe/email_sender.py b/scraibe/email_sender.py index 69c8cf9..b823039 100644 --- a/scraibe/email_sender.py +++ b/scraibe/email_sender.py @@ -455,112 +455,3 @@ def create_summary_docx( _add_summary_content(doc, text) doc.save(filename) - - -def send_success_email( - to: str, - transcript_text: str, - summary_text: str, - attachments: List[str], - task_id: str, -): - """ - Send a success email with attachments. - Subject is customizable via EMAIL_SUBJECT_SUCCESS. - Falls back to a safe default if the env var is missing or blank. - """ - # Read subject from environment; never allow blank - raw_subject = os.getenv("EMAIL_SUBJECT_SUCCESS") - subject = (raw_subject or "").strip() - - if not subject: - subject = "ScrAIbe: Your transcript is ready" - logger.info( - "EMAIL_SUBJECT_SUCCESS not set or blank; using default subject: %s", subject - ) - else: - logger.info("Using EMAIL_SUBJECT_SUCCESS: %s", subject) - - # Build email body - body = f""" -Your transcription is complete. - -Task ID: {task_id} - -Please find the attached documents: -- Transcript (MD) -- Transcript (DOCX) -- Source JSON -""" - if summary_text: - body += "- Summary (MD)\n- Summary (DOCX)\n" - - # Load HTML template - try: - html = load_template( - "success_template.html", - task_id=task_id, - transcript_text=transcript_text[:500], - summary_text=summary_text[:500] if summary_text else "", - ) - except EmailError: - html = None - - # Send email (send_email has an additional subject guard) - send_email( - to=to, - subject=subject, - body=body, - html=html, - attachments=attachments, - ) - - -def send_error_email( - to: str, - error_message: str, - task_id: str, -): - """ - Send an error email. - Subject is customizable via EMAIL_SUBJECT_ERROR. - Falls back to a safe default if the env var is missing or blank. - """ - # Read subject from environment; never allow blank - raw_subject = os.getenv("EMAIL_SUBJECT_ERROR") - subject = (raw_subject or "").strip() - - if not subject: - subject = "ScrAIbe: Error with your transcription request" - logger.info( - "EMAIL_SUBJECT_ERROR not set or blank; using default subject: %s", subject - ) - else: - logger.info("Using EMAIL_SUBJECT_ERROR: %s", subject) - - # Build email body - body = f""" -There was an error processing your transcription. - -Task ID: {task_id} -Error: {error_message} -""" - - # Load HTML template - try: - html = load_template( - "error_notification_template.html", - task_id=task_id, - error_message=error_message, - ) - except EmailError: - html = None - - # Send email (send_email has an additional subject guard) - send_email( - to=to, - subject=subject, - body=body, - html=html, - attachments=[], - ) diff --git a/scraibe/tasks.py b/scraibe/tasks.py index da8d1e9..e9d88e2 100644 --- a/scraibe/tasks.py +++ b/scraibe/tasks.py @@ -164,22 +164,10 @@ def send_success_email( Subject is customizable via EMAIL_SUBJECT_SUCCESS. Falls back to a safe default if the env var is missing or blank. """ - # Read subject from environment; never allow blank - raw_subject = os.getenv("EMAIL_SUBJECT_SUCCESS") - subject = (raw_subject or "").strip() - - if not subject: - subject = "ScrAIbe: Your transcript is ready" - logger.info( - "EMAIL_SUBJECT_SUCCESS not set or blank; using default subject: %s", subject - ) - else: - logger.info("Using EMAIL_SUBJECT_SUCCESS: %s", subject) - - # Final guard: ensure subject is never empty - if not subject: - subject = "ScrAIbe: Your transcript is ready" - logger.warning("Subject was empty after reading; forced default subject.") + subject = _get_subject( + "EMAIL_SUBJECT_SUCCESS", + "ScrAIbe: Your transcript is ready", + ) body = ( "Hello,\n\n"