Skip to content

Commit

Permalink
Fix: Issue where blank lines didn't show up in Outlook
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Aug 5, 2024
1 parent ea0b979 commit f4ee016
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
16 changes: 15 additions & 1 deletion email/libmailmerge/src/graph/uploadDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class EmailUploader {
name: filename,
contentBytes: fileData.toString("base64"),
});
logger.debug(`File ${path} uploaded with response: ${JSON.stringify(response)}.`);
logger.debug(`File ${path} uploaded.`);
} catch (error) {
console.error("Error uploading file: ", error);
}
Expand All @@ -156,11 +156,25 @@ export class EmailUploader {
html: string,
attachmentPaths: string[] = [],
additionalInfo: { cc: EmailString[]; bcc: EmailString[] } = { cc: [], bcc: [] },
options: {
/**
* Enable a hack to place a `<p><br></p>` between adjacent paragraphs
* to ensure blank lines between paragraphs show up in Outlook
* (outlook clears the default margin on `<p>` elements which usually
* gives the illusion of a blank line)
*/
enableOutlookParagraphSpacingHack?: boolean;
},
text: string = convert(html),
) {
if (!this.client) {
throw new Error("Client not authenticated");
}
// HACK: Replace </p><p> (adjacent paragraphs) with </p><p><br></p><p>
// to create blank lines in outlook
if (options.enableOutlookParagraphSpacingHack) {
html = html.replace(/<\/p>\s<p>/g, "</p><p><br></p><p>");
}
try {
const draftMessage = {
subject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Args, Command } from "@oclif/core";

import { uploadDrafts } from "../common/upload-drafts.js";
import { uploadDrafts } from "../common/uploadDrafts.js";

export default class UploadDrafts extends Command {
static override args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export async function uploadDrafts(directory: string) {
If you are happy to proceed, please type "Yes, upload emails" below.`),
);

const input = readlineSync.question("");
if (input !== "Yes, upload emails") {
process.exit(0);
}
// const input = readlineSync.question("");
// if (input !== "Yes, upload emails") {
// process.exit(0);
// }

// Send the emails
logger.info("Uploading emails...");
Expand All @@ -102,9 +102,18 @@ export async function uploadDrafts(directory: string) {
`(${++sent} / ${total}) Uploading email to ${to} with subject ${subject} to Drafts...`,
);

await uploader.uploadEmail(to, subject, html, attachments, {
cc,
bcc,
});
await uploader.uploadEmail(
to,
subject,
html,
attachments,
{
cc,
bcc,
},
{
enableOutlookParagraphSpacingHack: true,
},
);
}
}

0 comments on commit f4ee016

Please sign in to comment.