Mail
Edit a draft mail

Edit a draft mail

The secrecyClient.mail.updateDraft is a method that allows partial updates of draft emails in a secure way using the secrecyClient. It accepts a partial mail object of type NewMail as an argument, which includes details like the subject, body, recipients, any files from the sender SenderFiles, and an optional replyToId. The function first checks if secrecyClient is available, returning null if it’s not. If secrecyClient is available, it calls secrecyClient.mail.updateDraft with the properties from the mail object to update the draft and returns the resulting DraftMail.

mail.ts
type NewMail = {
  subject: string;
  body: string;
  replyToId: string | null;
  recipients: string[];
  senderFiles: {
    id: string;
    name: string;
  }[];
};
const updateDraftMail = async ({
  id,
  mail,
}: {
  id: string;
  mail: Partial<NewMail>;
}): Promise<DraftMail | null> => {
  // First we need to check if the secrecyClient is available
  if (!secrecyClient) {
    return null;
  }
 
  try {
    // return the updated draft mail
    const updatedDraftMail = await secrecyClient.mail.updateDraft(id, mail);
    return updatedDraftMail;
  } catch (error) {
    console.error(error);
    return null;
  }
};