Seth commited on
Commit ·
9c4a359
1
Parent(s): 3fdd55d
update
Browse files- backend/app/main.py +16 -3
backend/app/main.py
CHANGED
|
@@ -244,8 +244,9 @@ async def download_sequences(file_id: str = Query(...), db: Session = Depends(ge
|
|
| 244 |
contacts[contact_key]['bodies'][seq.email_number] = seq.email_content
|
| 245 |
|
| 246 |
# Create CSV in memory
|
|
|
|
| 247 |
output = io.StringIO()
|
| 248 |
-
writer = csv.writer(output)
|
| 249 |
|
| 250 |
# Write header with all subject/body columns
|
| 251 |
header = ['First Name', 'Last Name', 'Email', 'Company', 'Title', 'Product']
|
|
@@ -254,6 +255,7 @@ async def download_sequences(file_id: str = Query(...), db: Session = Depends(ge
|
|
| 254 |
writer.writerow(header)
|
| 255 |
|
| 256 |
# Write rows (one row per contact with all subjects/bodies)
|
|
|
|
| 257 |
for contact in contacts.values():
|
| 258 |
row = [
|
| 259 |
contact['first_name'],
|
|
@@ -264,8 +266,19 @@ async def download_sequences(file_id: str = Query(...), db: Session = Depends(ge
|
|
| 264 |
contact['product']
|
| 265 |
]
|
| 266 |
for i in range(1, 11):
|
| 267 |
-
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
writer.writerow(row)
|
| 270 |
|
| 271 |
output.seek(0)
|
|
|
|
| 244 |
contacts[contact_key]['bodies'][seq.email_number] = seq.email_content
|
| 245 |
|
| 246 |
# Create CSV in memory
|
| 247 |
+
# Use QUOTE_MINIMAL to properly quote fields with newlines for Smartlead
|
| 248 |
output = io.StringIO()
|
| 249 |
+
writer = csv.writer(output, quoting=csv.QUOTE_MINIMAL)
|
| 250 |
|
| 251 |
# Write header with all subject/body columns
|
| 252 |
header = ['First Name', 'Last Name', 'Email', 'Company', 'Title', 'Product']
|
|
|
|
| 255 |
writer.writerow(header)
|
| 256 |
|
| 257 |
# Write rows (one row per contact with all subjects/bodies)
|
| 258 |
+
# Preserve newlines in email bodies for proper formatting in Smartlead
|
| 259 |
for contact in contacts.values():
|
| 260 |
row = [
|
| 261 |
contact['first_name'],
|
|
|
|
| 266 |
contact['product']
|
| 267 |
]
|
| 268 |
for i in range(1, 11):
|
| 269 |
+
subject = contact['subjects'].get(i, '') or ''
|
| 270 |
+
body = contact['bodies'].get(i, '') or ''
|
| 271 |
+
|
| 272 |
+
# Convert newlines to HTML <br> tags for Smartlead to properly render line breaks
|
| 273 |
+
# Smartlead's rich text editor expects HTML formatting
|
| 274 |
+
if body:
|
| 275 |
+
# Replace newlines with <br> tags for HTML rendering in Smartlead
|
| 276 |
+
body_html = body.replace('\n', '<br>').replace('\r', '')
|
| 277 |
+
else:
|
| 278 |
+
body_html = ''
|
| 279 |
+
|
| 280 |
+
row.append(subject)
|
| 281 |
+
row.append(body_html)
|
| 282 |
writer.writerow(row)
|
| 283 |
|
| 284 |
output.seek(0)
|