当前位置: 首页>>代码示例>>Java>>正文


Java MessagePart类代码示例

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


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

示例1: scanParts

import com.google.api.services.gmail.model.MessagePart; //导入依赖的package包/类
private void scanParts(List<MessagePart> parts, Map<String, MessagePart> toDownload){
    for(MessagePart part : parts){
        LOGGER.info("Checking part "+part.getPartId()+" filename: "+part.getFilename());
        String filename = part.getFilename();
        String thisPuzzleName;
        if(filename != null && (filename.endsWith(".puz") || filename.endsWith(".jpz"))){
            thisPuzzleName = filename.substring(0, filename.lastIndexOf('.'));
            if(!toDownload.containsKey(thisPuzzleName)){
                LOGGER.info("Adding part for download "+thisPuzzleName+" "+part.getPartId());
                toDownload.put(thisPuzzleName, part);
            }
        } else if(part.getParts() != null && !part.getParts().isEmpty()){
            scanParts(part.getParts(), toDownload);
        }
    }
}
 
开发者ID:kebernet,项目名称:shortyz,代码行数:17,代码来源:GmailDownloader.java

示例2: getDataFromApi

import com.google.api.services.gmail.model.MessagePart; //导入依赖的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

示例3: download

import com.google.api.services.gmail.model.MessagePart; //导入依赖的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


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