@@ -7,34 +7,14 @@ Copyright (c) 2026 ClearCode Inc.
77*/
88import { ConfigLoader } from "./config-loader.mjs" ;
99import { MailDataCreator } from "./mail-data-creator.mjs" ;
10+ import { OfficeDataAccessHelper } from "./office-data-access-helper.mjs" ;
1011
1112Office . onReady ( ( ) => { } ) ;
1213
13- // function createNewMail() {
14- // try {
15- // const currentItemId = Office.context.mailbox.item.itemId;
16- // MailDataCreator.CreateReplyMailData();
17- // Office.context.mailbox.displayNewMessageFormAsync({
18- // toRecipients: Office.context.mailbox.item.to, // Copies the To line from current item
19- // ccRecipients: ["sam@contoso.com"],
20- // subject: "Outlook add-ins are cool!",
21- // htmlBody: 'Hello <b>World</b>!<br/><img src="cid:image.png"></i>',
22- // attachments: [
23- // {
24- // name: Office.context.mailbox.item.subject,
25- // type: Office.MailboxEnums.AttachmentType.Item,
26- // itemId: currentItemId,
27- // },
28- // ],
29- // });
30- // } catch (e) {
31- // console.log("createNewMail Failed:", e);
32- // }
33- // }
34-
3514async function onTypicalReplyButtonClicked ( event ) {
3615 const actionId = event . source . id ;
3716 console . log ( actionId ) ;
17+ console . log ( "conversationId: " + Office . context . mailbox . item . conversationId ) ;
3818 const config = await ConfigLoader . loadConfigForCurrentLanguage ( Office . context . displayLanguage ) ;
3919 const originalMailData = {
4020 toRecipients : Office . context . mailbox . item . to ,
@@ -45,26 +25,67 @@ async function onTypicalReplyButtonClicked(event) {
4525 subject : Office . context . mailbox . item . subject ,
4626 id : Office . context . mailbox . item . itemId ,
4727 } ;
28+ const abc = await OfficeDataAccessHelper . getAllMailData ( ) ;
29+ // Office.context.mailbox.item.displayReplyAllFormAsync({
30+ // htmlBody:
31+ // });
32+ console . log ( Office . context . mailbox . item . itemId ) ;
4833 try {
4934 const waitComplete = false ;
5035 for ( const buttonConfig of config . ButtonConfigList ) {
5136 if ( actionId !== buttonConfig . Id ) {
5237 continue ;
5338 }
54- const replyMailData = MailDataCreator . CreateReplyMailData ( { config : config . ButtonConfigList [ 0 ] , originalMailData } ) ;
55- Office . context . mailbox . displayNewMessageFormAsync ( replyMailData ) ;
39+ const replyMailData = MailDataCreator . CreateDataOnForReplyForm ( { config : config . ButtonConfigList [ 0 ] , originalMailData } ) ;
40+ if ( ! replyMailData ) {
41+ return event . completed ( ) ;
42+ }
43+ Office . context . roamingSettings . set ( targetConversationId , Office . context . mailbox . item . conversationId ?? "" ) ;
44+ Office . context . roamingSettings . set ( "buttonConfig" , JSON . stringify ( config . ButtonConfigList [ 0 ] ) ) ;
45+ Office . context . roamingSettings . saveAsync ( ) ;
46+ replyMailData . executeMethod ( { attachments : replyMailData . attachments } ) ;
47+ //Office.context.mailbox.displayNewMessageFormAsync(replyMailData,);
5648 // displayNewMessageFormAsync will be canceled if event.completed() is called
5749 // before finishing displayNewMessageFormAsync. The event will be completed
5850 // automatically after displayNewMessageFormAsync is called.
5951 waitComplete = true ;
6052 break ;
6153 }
62- if ( ! waitComplete ) {
63- event . completed ( ) ;
64- }
54+ event . completed ( ) ;
6555 } catch ( e ) {
6656 console . log ( "createNewMail Failed:" , e ) ;
6757 }
6858}
6959window . onTypicalReplyButtonClicked = onTypicalReplyButtonClicked ;
60+
61+ async function onNewMessageComposeCreated ( event ) {
62+ const id = Office . context . mailbox . item . conversationId ;
63+ const targetConversationId = Office . context . roamingSettings . get ( conversationId ) ?. trim ( ) ?? "" ;
64+ if ( id !== targetConversationId ) {
65+ event . completed ( ) ;
66+ }
67+ const buttonConfigJson = Office . context . roamingSettings . get ( "buttonConfig" ) ?. trim ( ) ?? "" ;
68+ Office . context . roamingSettings . remove ( conversationId ) ;
69+ Office . context . roamingSettings . remove ( "buttonConfig" ) ;
70+ Office . context . roamingSettings . saveAsync ( ) ;
71+ const buttonConfig = JSON . parse ( buttonConfigJson ) ;
72+ const currentSubject = await OfficeDataAccessHelper . getSubjectAsync ( ) ;
73+ const data = MailDataCreator . CreateReplyMailData ( { config : buttonConfig , currentSubject} ) ;
74+ if ( data . newToRecipients ) {
75+ await OfficeDataAccessHelper . setToAsync ( data . newToRecipients ) ;
76+ }
77+ await OfficeDataAccessHelper . setSubjectAsync ( data . subject ) ;
78+ let body = "" ;
79+ if ( data . quoteType ) {
80+ body = await OfficeDataAccessHelper . getBodyAsync ( ) ;
81+ }
82+ if ( data . bodyHtml ) {
83+ body = data . bodyHtml + "\n\n" + body ;
84+ }
85+ await OfficeDataAccessHelper . setBodyAsync ( body ) ;
86+ event . completed ( ) ;
87+ }
88+ window . onNewMessageComposeCreated = onNewMessageComposeCreated ;
89+
90+ Office . actions . associate ( "onNewMessageComposeCreated" , onNewMessageComposeCreated ) ;
7091Office . actions . associate ( "onTypicalReplyButtonClicked" , onTypicalReplyButtonClicked ) ;
0 commit comments