• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ListMessagesResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.api.services.gmail.model.ListMessagesResponse的典型用法代码示例。如果您正苦于以下问题:Java ListMessagesResponse类的具体用法?Java ListMessagesResponse怎么用?Java ListMessagesResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ListMessagesResponse类属于com.google.api.services.gmail.model包,在下文中一共展示了ListMessagesResponse类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: idInList

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
private boolean idInList(String testEmailId, ListMessagesResponse listOfMessages) {
    assertNotNull("list result", listOfMessages);
    assertTrue(!listOfMessages.getMessages().isEmpty());
    boolean foundMessage = false;
    for (Message m : listOfMessages.getMessages()) {
        if (testEmailId.equals(m.getId())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:GmailUsersMessagesIntegrationTest.java


示例2: idInList

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
private static boolean idInList(String testEmailId, ListMessagesResponse listOfMessages) {
    Assert.assertNotNull("list result", listOfMessages);
    List<Message> messages = listOfMessages.getMessages();
    if (messages != null) {
        for (Message m : listOfMessages.getMessages()) {
            if (testEmailId.equals(m.getId())) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:13,代码来源:GoogleMailIntegrationTest.java


示例3: getDataFromApi

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
private List<String> getDataFromApi(String query) throws IOException {
    List<String> messageList = new ArrayList<>();
    String user = "me";
    ListMessagesResponse response = mService.users().messages().list(user).setQ(query).execute();
    int total = 1;
    String deliverTo = "";
    String from = "";
    String subject = "";
    String content = "";
    long timestamp = 0;
    if (response.getMessages() != null) {
        for(int i = response.getMessages().size()-1;i>=0;i--){
            Message item = response.getMessages().get(i);
            if (total > mMaxResult) {
                break;
            }
            Message message = mService.users().messages().get(user, item.getId()).setFormat("full").execute();
            List<MessagePart> messageParts = message.getPayload().getParts();
            List<MessagePartHeader> headers = message.getPayload().getHeaders();

            if (!headers.isEmpty()) {
                for (MessagePartHeader header : headers) {
                    String name = header.getName();
                    switch (name) {
                        case "From":
                            from = header.getValue();
                            break;
                        case "To":
                            deliverTo = header.getValue();
                            break;
                        case "Subject":
                            subject = header.getValue();
                            break;
                        case "Date":
                            String date = header.getValue();
                            if(date.contains(","))
                                date = date.substring(date.indexOf(",") + 2,date.length());;
                            String timestampFormat = "dd MMM yyyy HH:mm:ss Z";
                            timestamp = TimeUtils.fromFormattedString(timestampFormat,date) / 1000;
                            break;
                    }
                }
            }
            if (messageParts != null && !messageParts.isEmpty()) {
                byte[] bytes = Base64.decodeBase64(messageParts.get(0).getBody().getData());
                if (bytes != null) {
                    String mailText = new String(bytes);
                    if (!mailText.isEmpty()) {
                        total++;
                        content = mailText;
                        messageList.add(mailText);
                    }
                }
            }
            if(mLastEmailTime < timestamp) mLastEmailTime = timestamp;
            this.output(new Email(content, AppUtils.APP_PACKAGE_GMAIL, from, deliverTo, subject, timestamp));
        }
    }

    //Reset the value for from and to
    mBegin = 0;
    mEnd = 0;
    return messageList;
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:65,代码来源:BaseGmailProvider.java


示例4: testMessages

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
@Test
public void testMessages() throws Exception {

    // ==== Send test email ====
    Message testEmail = createTestEmail();
    Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is com.google.api.services.gmail.model.Message
    headers.put("CamelGoogleMail.content", testEmail);

    com.google.api.services.gmail.model.Message result = requestBodyAndHeaders("direct://SEND", null, headers);
    assertNotNull("send result", result);
    String testEmailId = result.getId();

    // ==== Search for message we just sent ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    ListMessagesResponse listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertTrue(idInList(testEmailId, listOfMessages));

    // ===== trash it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://TRASH", null, headers);

    // ==== Search for message we just trashed ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertFalse(idInList(testEmailId, listOfMessages));

    // ===== untrash it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://UNTRASH", null, headers);

    // ==== Search for message we just trashed ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertTrue(idInList(testEmailId, listOfMessages));

    // ===== permanently delete it ====
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleMail.userId", CURRENT_USERID);
    // parameter type is String
    headers.put("CamelGoogleMail.id", testEmailId);
    requestBodyAndHeaders("direct://DELETE", null, headers);

    // ==== Search for message we just deleted ====
    headers = new HashMap<String, Object>();
    headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
    // using String message body for single parameter "userId"
    listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
    assertFalse(idInList(testEmailId, listOfMessages));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:68,代码来源:GmailUsersMessagesIntegrationTest.java


示例5: download

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
@Override
public File download(Date date) {
    LOGGER.fine("==starting gmail download....");
    try {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);
        Date after = calendar.getTime();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, 1);
        Date before = calendar.getTime();
        String query = "after:"+dateFormat.format(after)+" AND before:"+dateFormat.format(before)+" AND has:attachment AND (filename:.puz OR filename:.jpz)";
        LOGGER.info("Running query: "+query);
        ListMessagesResponse response = gmailService.users()
                .messages()
                .list("me")
                .setQ(query)
                .execute();
        LOGGER.fine("==Found "+ neverNull(response.getMessages()).size()+" messages.");
        for(Message message : neverNull(response.getMessages())){
            String singleFilename = "";

            Message fetched = gmailService.users().messages().get("me", message.getId())
                    .execute();
            LOGGER.fine("==Fetched message "+fetched.getId());
            HashMap<String, MessagePart> toDownload = new HashMap<>();
            scanParts(fetched.getPayload().getParts(), toDownload);
            for(Map.Entry<String, MessagePart> entry : toDownload.entrySet()){
                LOGGER.info("==Reading : "+singleFilename);
                String source = getSender(fetched.getPayload().getHeaders());
                @SuppressWarnings("deprecation") String filename = (date.getYear() + 1900) + "-" + (date.getMonth() + 1) + "-" + date.getDate() + "-" +
                        source+"-"+singleFilename.replaceAll(" ", "") + ".puz";
                File destination = new File(CROSSWORDS, filename);
                if(!destination.exists()){
                    byte[] data = entry.getValue().getBody().getAttachmentId() != null ?
                            gmailService.users().messages().attachments().get("me", message.getId(), entry.getValue().getBody().getAttachmentId()).execute().decodeData()
                            : entry.getValue().getBody().decodeData();
                    Puzzle puzzle = singleFilename.endsWith("jpz") ?
                            JPZIO.readPuzzle(new ByteArrayInputStream(data))
                            : IO.loadNative(new DataInputStream(new ByteArrayInputStream(data)));
                    puzzle.setDate(date);
                    puzzle.setSource(source);
                    puzzle.setSourceUrl("gmail://" + fetched.getId());
                    puzzle.setUpdatable(false);
                    date = getSentDate(fetched.getPayload().getHeaders());
                    LOGGER.info("Downloaded "+filename);
                    IO.save(puzzle, destination);
                }
            }


        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:kebernet,项目名称:shortyz,代码行数:58,代码来源:GmailDownloader.java


示例6: getRegistrationKeyFromGmail

import com.google.api.services.gmail.model.ListMessagesResponse; //导入依赖的package包/类
/**
 * Retrieve registration key sent to Gmail inbox. After retrieving, marks the email as read.
 *
 * @return registration key (null if cannot be found).
 */
public static String getRegistrationKeyFromGmail(String username, String courseName, String courseId)
        throws IOException, MessagingException {

    Gmail service = new GmailServiceMaker(username).makeGmailService();

    ListMessagesResponse listMessagesResponse;
    while (true) {
        try {
            // Get last 5 emails received by the user as there may be other emails received. However, this may fail
            // unexpectedly if there are 5 additional emails received excluding the one from TEAMMATES.
            listMessagesResponse = service.users().messages().list(username).setMaxResults(5L)
                    .setQ("is:UNREAD").execute();
            break;
        } catch (GoogleJsonResponseException e) {
            if (e.getDetails().getCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN) {
                System.out.println(e.getDetails().getMessage());
                service = new GmailServiceMaker(username, true).makeGmailService();
            } else {
                throw e;
            }
        }
    }

    final List<Message> messageStubs = listMessagesResponse.getMessages();

    if (isEmpty(messageStubs)) {
        return null;
    }

    for (Message messageStub : messageStubs) {
        final Message message = service.users().messages().get(username, messageStub.getId()).setFormat("raw")
                .execute();

        final MimeMessage email = convertFromMessageToMimeMessage(message);

        if (isStudentCourseJoinRegistrationEmail(email, courseName, courseId)) {
            final String body = getTextFromEmail(email);

            markMessageAsRead(service, username, messageStub);

            return getKey(body);
        }
    }

    return null;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:52,代码来源:EmailAccount.java



注:本文中的com.google.api.services.gmail.model.ListMessagesResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InputConnection类代码示例发布时间:2022-05-23
下一篇:
Java ReconfigurationException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap