Skip to content

Commit 4739a9a

Browse files
aleksandar888aleksandar.noveski
andauthored
feat(imap): implement email attachments support in IMAP plugin wrapper (#4927)
Co-authored-by: aleksandar.noveski <[email protected]>
1 parent e34c705 commit 4739a9a

File tree

1 file changed

+40
-2
lines changed
  • src/@awesome-cordova-plugins/plugins/imap

1 file changed

+40
-2
lines changed

src/@awesome-cordova-plugins/plugins/imap/index.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,13 @@ export interface Content {
191191
*/
192192
type: string;
193193
/**
194-
* Optional. The name of the file.
194+
* The name of the file, if the message content is a file attachment.
195195
*/
196-
fileName?: string;
196+
fileName: string;
197+
/**
198+
* Android ONLY. Optional. "contentID" is a unique identifier for the attachment, used to fetch the file. It is preferred over "fileName" when available.
199+
*/
200+
contentID?: string;
197201
/**
198202
* Message's content.
199203
*/
@@ -454,6 +458,17 @@ export enum FlagEnum {
454458
* console.error(error)
455459
* });
456460
*
461+
* * Download Email Attachment
462+
* * The 'contentID' (the last parameter) can be set to an empty string ('') or null if it's not provided.
463+
* this.imap.downloadEmailAttachment('INBOX', 1545, '/storage/emulated/0/Download', false, 'image001.png', '<f_lqqj1d851>')
464+
* .then((res: boolean) => {
465+
* // Returns "true" if the attachment is successfully saved, else returns "false".
466+
* console.log(res)
467+
* })
468+
* .catch((error: any) => {
469+
* console.error(error)
470+
* });
471+
*
457472
* ```
458473
*/
459474
@Plugin({
@@ -617,4 +632,27 @@ export class Imap extends AwesomeCordovaNativePlugin {
617632
setFlag(folderName: string, messageNums: number[], flag: FlagEnum, status: boolean): Promise<ModificationResult> {
618633
return;
619634
}
635+
636+
/**
637+
* "downloadEmailAttachment(folderName: string, messageNo: number, path: string, replaceIfDuplicate: boolean, fileName: string, contentID: string)"
638+
* Download email attachment using "fileName" or "contentID" – Android only. "contentID" is preferred when available, and it works only on Android.
639+
* @param folderName {string} The name of the desired folder.
640+
* @param messageNo {number} Message's consecutive number.
641+
* @param path {string} The file path where the attachment should be saved.
642+
* @param replaceIfDuplicate {boolean} When set to true, duplicate attachments are overwritten, when set to false, the file name is modified by appending a suffix (e.g., file_name (1).type) to avoid overwriting.
643+
* @param fileName {string} The name of the attachment to be downloaded.
644+
* @param contentID {string} Optional parameter. Android ONLY. The "contentID" of the attachment to be downloaded. This parameter is preferred if available.
645+
* @return {Promise<boolean>} Returns boolean status of the process.
646+
*/
647+
@Cordova()
648+
downloadEmailAttachment(
649+
folderName: string,
650+
messageNo: number,
651+
path: string,
652+
replaceIfDuplicate: boolean,
653+
fileName: string,
654+
contentID: string
655+
): Promise<boolean> {
656+
return;
657+
}
620658
}

0 commit comments

Comments
 (0)