from pathlib import Path import pytest from tempfile import TemporaryDirectory @pytest.fixture def tmp_dir(): tmp_dir = TemporaryDirectory(delete=False) print("Created temporary directory ", tmp_dir.name) yield tmp_dir.name print("Cleaned temporary directory", tmp_dir.name) tmp_dir.cleanup() @pytest.fixture def test_email(tmp_dir): test_contents = """ Return-Path: sender@example.com Delivered-To: recipient@example.org Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by mx.example.org (Postfix) with ESMTPS id 7B94C160C72 for recipient@example.org; Wed, 16 Apr 2025 09:23:45 -0700 (PDT) Received: by mail-yw1-f174.google.com with SMTP id 5so12345678ywa.9 for recipient@example.org; Wed, 16 Apr 2025 09:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=20210112; h=from:to:subject:date:message-id:mime-version ; bh=q3rblHeObV5Ov3/B7+E3yRlCopVAn6Mkt14vBcAXxTM=; b=QC2U9YyGp6HR5NvBxnv7y4MNO1OrF9dhZwPz+1G2FpvTZ3jrREi8W8tNkE8ys9f9Hd GnQDUuFZqDWS9S3IxGu7CHfrFSX/5kVAVxnGK58BqJsvjtJeZ9iKjDDt8XCMQaXfJo9s /s7UMz3C+8lXe5BqVvZXjjgTgDG5tDyb8tRNc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; h=from:to:subject:date:message-id:mime-version :thread-index ; bh=q3rblHeObV5Ov3/B7+E3yRlCopVAn6Mkt14vBcAXxTM=; b=xyUdZMdwCGQr9bxLnOd8jBRiTDBw6LPSRkEXYzYP3yDJLYxzqA3vNh/0KoNMBTF5qF EkCGxbBz74vvGpDLUSRKBmgXNRlLlfN93O/QfF4IxLuQg4OLITi6QvtOgVb/iHFwUGcE TmLMSYgDd93cw+YXqMtZKztB7/1+4MjCYxUQs= X-Gm-Message-State: AOJu0Yy5DBCExZB2/PXGZJRbipzjPKFQEpdnHvMwkbCJd6Bd/xuvCeDb JGGsOxfyFXeHYd0J3nPGOg== X-Google-Smtp-Source: AGHT+IGQyWQO69p9mhCHt5N5NbKLfb9Ij9fgRFGjk+UJNpRo3S9VPDV6pXXucyU0xAL3AiT5jNtO16w= X-Received: by 2002:a25:fb02:0:b0:664:f31a:2be0 with SMTP id u2-20020a25fb02000000b00664f31a2be0mr13538287ybg.36.1713373420812; Wed, 16 Apr 2025 09:23:40 -0700 (PDT) From: "John Doe" sender@example.com To: recipient@example.org Subject: Sample email for parsing exercises Date: Wed, 16 Apr 2025 12:23:35 -0400 Message-ID: 7a8b9c0d1e2f3g4h5i6j@mail.example.com MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thread-Index: AQHZpT2RwxyzABCDEFghijkLMNO= Content-Language: en-US X-Spam-Status: No, score=-0.8 X-Spam-Score: -0.8 X-Spam-Bar: - X-Ham-Report: Spam detection software, running on the system "mailserver.example.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. X-Spam-Flag: NO Hello, This is a sample email that can be used for parsing exercises. The email includes all standard headers that would be present in a typical email message. The content of this message is kept simple to focus on the structure and headers. You can use this example to test email parsing scripts, to understand email format, or to demonstrate how email headers work. Some key points about email headers: They contain routing information They show authentication results (DKIM, SPF) They include sender and recipient details They contain timestamps and unique identifiers Feel free to modify this template as needed for your specific parsing requirements. Regards, John Doe -- John Doe Senior Developer Example Corp Phone: (555) 123-4567 """ email_path = Path(tmp_dir) / "test_email.txt" with open(email_path, "w") as f: f.write(test_contents) yield email_path