2

We implemented a function to create drafts using Compose Actions.
However, the subject is garbled.
If the subject is あいうえお, it will be Re: BDFHJ.
I want to prevent garbled characters.

this code.

Code.js

function buildCard (e) {
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle("タイトル"));
  var section = CardService.newCardSection();
  var composeAction = CardService.newAction()
    .setFunctionName('createReplyDraft');
  var composeButton = CardService.newTextButton()
    .setText('Compose Reply')
    .setComposeAction(composeAction, CardService.ComposedEmailType.REPLY_AS_DRAFT);
  section.addWidget(composeButton);
  card.addSection(section);
  return card.build();
}

/**
 *  Creates a draft email (with an attachment and inline image)
 *  as a reply to an existing message.
 *  @param {Object} e data passed by the compose action.
 *  @return {ComposeActionResponse}
 */
function createReplyDraft(e) {
  // Activate temporary Gmail add-on scopes, in this case to allow
  // a reply to be drafted.
  var accessToken = e.messageMetadata.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);

  // Creates a draft reply.
  var messageId = e.messageMetadata.messageId;
  var message = GmailApp.getMessageById(messageId);
  var draft = message.createDraftReply('あいうえお');  //There is no problem with body.

  // Return a built draft response. This causes Gmail to present a
  // compose window to the user, pre-filled with the content specified
  // above.
  return CardService.newComposeActionResponseBuilder()
    .setGmailDraft(draft).build();
}

appsscript.json

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.readonly"
  ],
  "gmail": {
    "name": "Gmail Add-on Quickstart",
    "logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
    "contextualTriggers": [{
      "unconditional": {
      },
      "onTriggerFunction": "buildCard"
    }],
    "openLinkUrlPrefixes": [
      "https://mail.google.com/"
    ],
    "primaryColor": "#4285F4",
    "secondaryColor": "#4285F4"
  },
  "oauthScopes":[ 
    "https://mail.google.com/",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/script.external_request"]
}

this flow.

step1. You've got mail.

enter image description here

step2. Click the Compose Reply enter image description here

step3. Edit Subject. enter image description here

step4. Subject is garbled. enter image description here

haneta
  • 21
  • 2
  • Unfortunately, in my environment, I couldn't replicate your situation. I can use gmail with old or new version. And I don't modify my gmail and use the default settings. For this situation, can you provide the detail flow for replicating your situation? – Tanaike Sep 03 '18 at 23:30
  • It seems you have declared your OAuth scopes twice... – tehhowch Sep 04 '18 at 02:11
  • I made a mistake that oauthScopes declared twice. Even if you delete it, it is the same behavior. – haneta Sep 04 '18 at 02:28
  • Thank you for adding them. I could also confirm the same situation. When ``あ`` is converted to UTF-16 and the lower 2 bytes are retrieved, the value is 42. In your situation, the character code of "0042" is used and ``B`` is returned. For example, ``\u3042\u0042`` is used to the subject, ``BB`` is returned. It is considered that such conversion occurs in this case. If the character code can be set when ``createDraftReply()`` is used, the correct values might be returned. But in the current situation, it cannot be done. – Tanaike Sep 05 '18 at 02:31
  • This is already mentioned as an issue on Google Issue Tracker: https://issuetracker.google.com/issues/78142881 "Subject garbled when creating a draft reply if the original subject uses Japanese characters" – haneta Sep 05 '18 at 05:11

0 Answers0