我正在尝试编写GMAIL上下文小工具。 我准备好了所有构建块(服务,小工具,manifest.repositories ......) 基本的你好世界工作正常。
简化说," 我最喜欢马克"我的小部件中的功能
我需要存储(在我的SQL数据库中)某些标记为收藏邮件的对象。
随着邮件打开,我的小部件将加载,现在我想对我的数据库进行ajax调用,并检查"这个特定的邮件"是不是最喜欢的邮件。
问:我在我的java脚本中只需要一个唯一的消息ID ,以便每当有任何用户将电子邮件标记为收藏时。我会将该唯一消息ID存储在我的数据库中的收藏夹列表中。
清单
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<!-- Support info to show in the marketplace & control panel -->
<Support>
<!-- URL for application setup as an optional redirect during the install -->
<Link rel="setup" href="https://www.google.com" />
<!-- URL for application configuration, accessed from the app settings
page in the control panel -->
<Link rel="manage" href="https://www.google.com" />
<!-- URL explaining how customers get support. -->
<Link rel="support" href="https://www.google.com" />
<!-- URL that is displayed to admins during the deletion process,
to specify policies such as data retention, how to claim accounts, etc. -->
<Link rel="deletion-policy" href="https://www.google.com" />
</Support>
<!-- Name and description pulled from message bundles -->
<Name>HelloWorld</Name>
<Description>A simple Hello World application for testing
Gmail contextual gadgets</Description>
<!-- Show this link in Google's universal navigation for all users -->
<Extension id="navLink" type="link">
<Name>HelloWorld</Name>
<Url>http://www.google.com</Url>
</Extension>
<!-- Declare our OpenID realm so our app is white listed -->
<Extension id="realm" type="openIdRealm">
<Url>http://_example.com_</Url>
</Extension>
<!-- EXTRACTOR -->
<Extension id="HelloWorldExtractor" type="contextExtractor">
<Name>Hello World</Name>
<Url>google.com:HelloWorld</Url>
<!-- Uncomment this Param to apply a filter to the extractor's
default output. The example regexp below makes the match case sensitive.
<Param name="hello" value="H[a-z]* W[a-z]*"/> -->
<Triggers ref="HelloWorldGadget"/>
<Scope ref="emailSubject"/>
<Scope ref="emailBody"/>
<Container name="mail"/>
</Extension>
<!-- GADGET -->
<Extension id="HelloWorldGadget" type="gadget">
<Name>Hello World Gmail contextual gadget</Name>
<Url>mydomain/widget-module.xml</Url>
<Container name="mail"/>
<!-- Uncomment this to enable Caja. -->
<!-- <Param name="caja" value="enabled"/> -->
</Extension>
<!-- SCOPE -->
<Scope id="emailSubject">
<Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
<Reason>This application searches the Subject: line of each email
for the text "Hello World."</Reason>
</Scope>
<Scope id="emailBody">
<Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
<Reason>This application searches the message body of each email
for the text "Hello World."</Reason>
</Scope>
</ApplicationManifest>
小部件
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Hello World"
description="Matches and echoes 'Hello World' string in emails"
height="20"
author="Sarah M and Walter Q"
author_email="..."
author_location="Mountain View, CA">
<!-- Declare feature dependencies. -->
<!-- This one is not specific to Gmail contextual gadgets. -->
<Require feature="dynamic-height"/>
<!-- The next feature, Caja, is optional, and is supported for
use only within test domains. Uncomment the tag only for
non-production gadgets. -->
<!-- <Require feature="caja"/> -->
<!-- The next feature, google.contentmatch, is required for all
Gmail contextual gadgets.
<Param> - specify one or more comma-separated extractor IDs in
a param named "extractors". This line is overridden by the extractor ID
in the manifest, but is still expected to be present. -->
<Require feature="google.contentmatch">
<Param name="extractors">
google.com:HelloWorld
</Param>
</Require>
</ModulePrefs>
<!-- Define the content type and display location. The settings
"html" and "card" are required for all Gmail contextual gadgets. -->
<Content type="html" view="card">
<![CDATA[
<!-- Start with Single Sign-On -->
<script type="text/javascript" src="https://example.com/gadgets/sso.js"></script>
<script type="text/javascript">
<!-- Fetch the array of content matches. -->
matches = google.contentmatch.getContentMatches();
var matchList = document.createElement('UL');
var listItem;
var extractedText;
//**I JUST WANT THE UNIQUE MESSAGE ID OVER HERE**
<!-- Iterate through the array and display output for each match. -->
for (var match in matches) {
for (var key in matches[match]) {
listItem = document.createElement('LI');
extractedText = document.createTextNode(key + ": " + matches[match][key]);
listItem.appendChild(extractedText);
matchList.appendChild(listItem);
}
}
document.body.appendChild(matchList);
gadgets.window.adjustHeight(100);
</script>
]]>
</Content>
</Module>
如果在这里,我只需要一些独特的信息:
// 我只想在这里找到唯一的消息ID
编辑=========================================== ===================================
根据建议,我做了以下更改:
我的宣言:
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<!-- Support info to show in the marketplace & control panel -->
<Support>
<!-- URL for application setup as an optional redirect during the install -->
<Link rel="setup" href="https://www.google.com" />
<!-- URL for application configuration, accessed from the app settings
page in the control panel -->
<Link rel="manage" href="https://www.google.com" />
<!-- URL explaining how customers get support. -->
<Link rel="support" href="https://www.google.com" />
<!-- URL that is displayed to admins during the deletion process,
to specify policies such as data retention, how to claim accounts, etc. -->
<Link rel="deletion-policy" href="https://www.google.com" />
</Support>
<!-- Name and description pulled from message bundles -->
<Name>HelloWorld</Name>
<Description>A simple Hello World application for testing
Gmail contextual gadgets</Description>
<!-- Show this link in Google's universal navigation for all users -->
<Extension id="navLink" type="link">
<Name>HelloWorld</Name>
<Url>http://www.google.com</Url>
</Extension>
<!-- Declare our OpenID realm so our app is white listed -->
<Extension id="realm" type="openIdRealm">
<Url>http://_example.com_</Url>
</Extension>
<Extension id="uniqueId" type="contextExtractor">
<Name>Custom_Extractor_7</Name>
<Url>sample2ForUniqueReceipients:Custom_Extractor_7</Url>
<Triggers ref="HelloWorldGadget" />
<Scope ref="senderScope" />
<Container name="mail" />
</Extension>
<!-- EXTRACTOR
<Extension id="from" type="contextExtractor">
<Name>Email Sender</Name>
<Url>google.com:SenderEmailExtractor</Url>
<Param name="sender_email" value="amalhotra@ivp.in"/>
<Triggers ref="HelloWorldGadget"/>
<Scope ref="senderScope"/>
<Container name="mail"/>
</Extension>
<Extension id="MessageID" type="contextExtractor">
<Name>Message ID Extractor</Name>
<Url>google.com:MessageIDExtractor</Url>
<Param name="message_id" value=".*"/>
<Triggers ref="HelloWorldGadget"/>
<Scope ref="messageID"/>
<Container name="mail"/>
</Extension>
-->
<!-- GADGET -->
<Extension id="HelloWorldGadget" type="gadget">
<Name>Hello World Gmail contextual gadget</Name>
<Url>MY_GADGET_URL</Url>
<Container name="mail"/>
<!-- Uncomment this to enable Caja. -->
<!-- <Param name="caja" value="enabled"/> -->
</Extension>
<!-- SCOPE -->
<Scope id="emailSubject">
<Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
<Reason>This application searches the Subject: line of each email
for the text "Hello World."</Reason>
</Scope>
<Scope id="emailBody">
<Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
<Reason>This application searches the message body of each email
for the text "Hello World."</Reason>
</Scope>
<Scope id="messageID">
<Url>tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID</Url>
<Reason>This application searches the message header of each email
for the text.</Reason>
</Scope>
<Scope id="emailMessageId">
<Url>tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID</Url>
<Reason>This would get the message id and most probalbly trigger the widget</Reason>
</Scope>
<Scope id="senderScope">
<Url>tag:google.com,2010:auth/contextual/extractor/FROM_ADDRESS</Url>
<Reason>This application searches the Subject: line of each email
for the text "Hello World."</Reason>
</Scope>
</ApplicationManifest>
自定义提取器
<?xml version="1.0" encoding="UTF-8"?>
<OpenCOBData id="Custom_Extractor_7">
<ExtractorSpec platform="gmail" language="en">
<Search>
<Pattern input_fields="from_email">
<![CDATA[(myemailaddress@mydomain.in)]]>
</Pattern>
</Search>
<Response platform="gmail" format="cardgadget">
<Output name="id">{@__MESSAGE_ID__}</Output>
<Output name="sender">{@__FROM_ADDRESS__}</Output>
<Output name="date">{@__DATE_SENT__}</Output>
<Output name="to">{@__TO_ADDRESS__}</Output>
<!--Output name="email_subject">{@__SUBJECT__}</Output>
<Output name="received_date">{@__DATE_RECEIVED__}</Output-->
</Response>
</ExtractorSpec>
</OpenCOBData>
答案 0 :(得分:1)
使用消息ID提取器,它将为您提供前端唯一消息ID。
提取器详细信息:
ID = google.com:MessageIDExtractor
Description = Matches the Gmail frontend message id of the message (this is a 64-bit hexadecimal value, different from the RFC 822 Message-ID)
Scope = tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID
Output Fields = @message_id - Message ID of the message
答案 1 :(得分:1)
使用此提取器:
<?xml version="1.0" encoding="UTF-8"?>
<OpenCOBData id="Custom_Extractor_7">
<ExtractorSpec platform="gmail" language="en">
<Search>
<Pattern input_fields="from_email">
<![CDATA[(email_1|email_2|email_3)]]>
</Pattern>
</Search>
<Response platform="gmail" format="cardgadget">
<Output name="id">{@__MESSAGE_ID__}</Output>
<Output name="sender">{@__FROM_ADDRESS__}</Output>
<Output name="date">{@__DATE_SENT__}</Output>
<Output name="to">{@__TO_ADDRESS__}</Output>
<!--Output name="email_subject">{@__SUBJECT__}</Output>
<Output name="received_date">{@__DATE_RECEIVED__}</Output-->
</Response>
</ExtractorSpec>
</OpenCOBData>
在下面的行中,将email_1,email_2,email_3替换为您要匹配的电子邮件,并添加您想要的内容。
<![CDATA[(email_1|email_2|email_3)]]>
答案 2 :(得分:0)
你必须在Mamifiest中添加它的引用,如下所示,
它也将进入googleapps控制台中的提取器(可选)部分。
在此类清单中引用:
<Extension id="uniqueId" type="contextExtractor">
<Name>Custom_Extractor_7</Name>
<Url> ProjectID:ExtractorId</Url>
<Triggers ref="GadgetID" />
<Scope ref="ScopeId" />
<Container name="mail" />
</Extension>
此处项目ID是您在Google Apps控制台上创建的项目的ID。
Extractor ID是自定义提取器的ID。
Gadget Id是您的清单中存在的小工具部分的ID。
并且Scope Id是您的清单中存在的范围部分的ID,您可以添加多个范围,这些范围对应于提取器的输出。