Metadata-Version: 2.4
Name: django-outlook-sync-inbox
Version: 1.0.8
Summary: A production-ready Django application package to automate background syncing of local desktop Outlook emails with both HTML and REST API interfaces.
Author-email: Yonas <yonas2754@gmail.com>
Classifier: Framework :: Django
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: pywin32; sys_platform == "win32"
Requires-Dist: schedule>=1.2.0
Requires-Dist: djangorestframework>=3.14.0


```markdown
# Django Outlook Sync Inbox

A production-ready Django application package designed to automate background syncing of local desktop Outlook emails into your Django database application space, exposing both an administrative HTML Monitoring Dashboard and clean, lightweight JSON REST API endpoints.

---

## 🚀 Key Features

* **Background Daemon Process:** Keeps a light, standalone background loop active to scrape emails automatically using the Windows background environment.
* **Strict Recipient Filtering:** Restricts email ingestion to specific targeted email addresses.
* **Smart Loop & Thread Protection:** Strips legacy thread data and ignores thread replies (`RE:`, `FW:`) during automated reply executions to avoid looping cascades.
* **Data Extraction Pipeline:** Statically extracts inline attachments/images and returns ONLY the core body statement string via its REST API payload.
* **Django Admin Integration:** Automatically registers models so you can view, search, and manage incoming messages via the built-in admin panel.

---

## 🛠️ Step 1: Installation & Setup

Install your library using Python's package manager inside your active project virtual environment:

```powershell
pip install django-outlook-sync-inbox==1.0.8

```

---

## ⚙️ Step 2: Framework Configuration

Open your target Django project's main **`settings.py`** file and register your configurations.

### 1. Register Apps in `INSTALLED_APPS`

Add the core Django REST Framework along with your newly installed library package namespace:

```python
INSTALLED_APPS = [
    # ... Django base core apps ...
    
    'rest_framework',
    'django_outlook_sync',  # Core application directory mapping
]

```

### 2. Append Custom Parameters Block

Scroll to the bottom of **`settings.py`** and define your strict processing criteria limits:

```python
# ==============================================================================
# DJANGO OUTLOOK SYNC CONFIGURATION SYSTEM
# ==============================================================================

# Case-insensitive string filters matching fields found in TO or CC email headers
OUTLOOK_ALLOWED_RECIPIENTS = [
    "abebe kebede chale",
    "yonas mulugeta teruwha
]

# Customized automated HTML notification template receipt string emailed back to senders
OUTLOOK_REPLY_TEMPLATE = """
<p>Hello,</p>
<p>Your email has been received and processed successfully by our new system application.</p>
<p>Thank you.</p>
"""

```

---

## 🗄️ Step 3: Database Migrations & URLs

### 1. Apply Layout Migrations

Generate and run the schema structural layout blueprints inside your project directory database using management commands:

```powershell
python manage.py makemigrations django_outlook_sync
python manage.py migrate

```

### 2. Include Routing Rules in `urls.py`

Expose your component interfaces inside your core primary app routing table **`myproject/urls.py`**:

```python
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    
    # Mounts all user interfaces and API endpoints under the /outlook/ prefix
    path('outlook/', include('django_outlook_sync.urls')),
]

```

---

## 🔑 Step 4: First-Time Setup (Crucial)

Before you fire up the background automation script, you must open the communication bridge on your desktop:

1. **Open your Microsoft Outlook desktop application.**
2. **Ensure you are logged into your profile account** and your inbox is active.
3. **Leave the Outlook application running** (you can minimize it) in the background.

---

## ⏰ Step 5: Running the Background Daemon Engine

Once Outlook is running on your desktop, open a separate dedicated console terminal window, make sure your virtual environment is active, and fire up your global tracking loop macro command line executable:

```powershell
django-outlook-daemon

```

*Note: If your local path configuration does not support global entry script maps, you can run the internal package entry point module pathway explicitly instead:*

```powershell
python -m django_outlook_sync.auto_sync

```

---

## 🖥️ Step 6: How to view the final output

Once your background daemon engine is running and processing inbound traffic sequences, open your web browser to check the final application results via these distinct channels:

### Output Interfaces Reference Guide

| Interface Description | Targeted Endpoint URL Route | Output Content Payload Structure |
| --- | --- | --- |
| **Django Admin Board** | `http://127.0.0.1:8000/admin/django_outlook_sync/emailmessage/` | The built-in Django administrative panel to search, filter, and view synced email rows. |
| **HTML Mailbox UI Monitor** | `http://127.0.0.1:8000/outlook/inbox/` | A production-ready dashboard grid displaying all ingested database email rows. |
| **REST JSON Array Endpoint** | `http://127.0.0.1:8000/outlook/api/emails/` | Returns a serialized array of data containing hidden raw IDs and parsed body statements. |
| **Single Ingest Details Lookup** | `http://127.0.0.1:8000/outlook/api/emails/1/` | Detailed profile lookup tracking a specific email instance item row. |

### Clean REST API Output Sample Result

The background processing engine filters out dense Microsoft Word/Outlook XML tags and header data structures, returning a lightweight JSON object containing **only the final statement string**:

```json
[
    {
        "id": 1,
        "subject": "test3",
        "sender": "Yonas Mulugeta Teruwha",
        "recipients": "Yonas Mulugeta Teruwha",
        "cc_recipients": "",
        "received_at": "2026-06-22T04:14:00Z",
        "is_thread_reply": false,
        "created_at": "2026-06-22T04:17:05.717684Z",
        "html_body": "Test3"
    }
]

```

---

## 🛑 Troubleshooting

* **Loop / Double Processing:** The engine evaluates text signatures across raw and text objects. If your custom reply template text structure changes, update the validation string definitions within your script files to ensure thread containment checks continue functioning correctly.
* **Missing Images:** Static assets are served locally using your primary web server engine context. Ensure `django.contrib.staticfiles` handles paths properly inside your global server properties configurations.

```

```
