Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1848|回复: 5
打印 上一主题 下一主题

接收时间和发送时间

[复制链接]

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
跳转到指定楼层
楼主
发表于 2016-4-20 23:31:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. nsParseMailbox.cpp中
  2. int nsParseMailMessageState::ParseHeaders ()这个函数对返回的日期串的解析,对于126邮件从一个文件夹移动到另一个文件夹中的操作,不知为什么传过来的时间总是当前的时间
  3. 造成每次移动后,原来的日期都不能正常显示,目前只是判断了如果 received 中的时间比 date中的时间新的话,则使用date的时间,具体为什么会传当前时间还要分析(实际过程:要移动的邮件copy完成后,会重新获取一下新位置的邮件信息,而126返回的串的日期是不正确的)
  4. 抓包先进行下面两个操作
  5. 146 uid copy 2166 "&V4NXPpCuTvY-"
  6. 146 OK COPY completed
  7. 147 uid store 2166 +FLAGS (\Deleted \Seen)
  8. * 5 FETCH (FLAGS (\Deleted \Seen) UID 2166)
  9. 147 OK STORE completed

  10. 后面再获取:
  11. 7 UID fetch 1383299324 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Received Priority X-Priority References Newsgroups In-Reply-To Content-Type)])

  12. * 16 FETCH (UID 1383299324 FLAGS (\Seen) RFC822.SIZE 1738 BODY[HEADER.FIELDS (FROM TO CC BCC SUBJECT DATE MESSAGE-ID RECEIVED PRIORITY X-PRIORITY REFERENCES NEWSGROUPS IN-REPLY-TO CONTENT-TYPE)] {393}

  13. Content-Type: multipart/alternative;

  14. boundary="------------080906050404020303020606"

  15. Date: 2014-04-28 16:22:18

  16. From: he <hechengjin@richinfo.cn>

  17. Message-ID: <535E0FBA.5010404@richinfo.cn>

  18. Received: from hechengjin88 (unknown [58.61.30.34:26778])

  19. .by IMAP (Coremail) with SMTP id Oj3h3QDHMhkEgWdT;

  20. .Mon, 05 May 2014 20:16:21 +0800 (CST)

  21. Subject: xxxx

  22. To: he <hechengjin88@126.com>



  23. )

  24. 7 OK Fetch completed

  25. 即在移动邮件后,新邮件夹中每次重新从服务端获取新到的邮件的头信息,而不是读取本地的邮件信息,而从服务端返回的信息中日期是不正确的。
  26. 如何触发获取新邮件消息头的,本地又是如何存储的,移动的过程中除了在服务端执行命令外,本地双进行了哪些操作/ 这个过程能不能不请求服务端的消息头。
  27. nsParseMailbox.cpp
  28. 读信页显示窗口时间的修改msghdrviewOverlay.js
  29. 增加通过 x-richinfo-localizeddate-received 获取时间值
  30. nsMimeHtmlEmitter.cpp
  31. 中增加 x-richinfo-localizeddate-received  获取对 received中日期解析及获取
  32. 关联字段的修改
  33. nsMsgDBView.cpp
  34. nsMsgDBView::CellTextForColumn
  35. case 'd':  // date
  36.   {
  37.     rv = FetchDate(msgHdr, aValue,true);

  38. 协议解析的修改
  39. nsParseMailbox.cpp
  40. nsParseMailMessageState:: ParseHeaders

  41. case 'R': case 'r':
  42. nsParseMailMessageState:: ParseFolderLine
  43. nsParseMailMessageState:: ParseAFolderLine
  44. nsImapMailFolder.cpp
  45. nsImapMailFolder:: ParseAdoptedHeaderLine
  46. nsImapMailFolder:: ParseMsgHdrs

  47. IMAP请求的修改nsImapProtocol.cpp
  48. #define IMAP_ENV_HEADERS "From To Cc Bcc Subject Date Message-ID Received "   最后加上一个空格,要不和后面的连接在一起了
  49. #define IMAP_DB_HEADERS "Priority X-Priority References Newsgroups In-Reply-To Content-Type"
  50. #define IMAP_ENV_AND_DB_HEADERS IMAP_ENV_HEADERS IMAP_DB_HEADERS

  51. 发送的请求
  52. 7 UID fetch 1382926263 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Received Priority X-Priority References Newsgroups In-Reply-To Content-Type)])

  53. http://forums.mozillazine.org/viewtopic.php?f=39&t=729645http://forums.mozillazine.org/viewtopic.php?f=39&t=640808

  54. Set the variable:
  55. mailnews.use_received_date = true (boolean)

  56. If you are using a POP3 account, that should suffice.

  57. For a IMAP account, you should set also:
  58. mailnews.customDBHeaders = Received (string)
  59. In this way, the "Received" column will not be identical to the "Date" column anymore; now it shows the reception date on your mail server, that is generally considered to be a better choice.


  60. 扩展  通过mailnews.customDBHeaders开关
  61. https://addons.mozilla.org/zh-cn/thunderbird/addon/imap-received-date/
复制代码
imap_received_date-1.0-tb sm.rar (4.85 KB, 下载次数: 0)
回复

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
沙发
 楼主| 发表于 2016-4-20 23:32:21 | 只看该作者
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
板凳
 楼主| 发表于 2016-4-20 23:32:39 | 只看该作者
本帖最后由 hechengjin 于 2016-4-20 23:34 编辑

mailnews.display.date_senders_timezone; 为true 读信页会显示时区
  1. mailnews/local/src/nsParseMailbox.cpp
  2. int nsParseMailMessageState::ParseHeaders ()
复制代码
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
地板
 楼主| 发表于 2016-4-20 23:34:12 | 只看该作者
目前的方案:收件箱里显示的是smtp服务器的时间,即received里的时间,而已发送里显示的是当前系统的时间即 data 里的时间,当两者不一致时会有出入.
另外收件箱里,只有data里的时间比smtp里的时间还早时,会显示data时间,这个是为了防止在移动邮件时,老是出现时间为执行当前操作的时间,原来的时间都找不到了,具体细节还要研究
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
5#
 楼主| 发表于 2016-4-20 23:35:15 | 只看该作者
D:\svn\Client\ThinkMail_ClientWin_2013\trunk\src\thinkmail\mailnews\mime\src\mimedrft.cpp

#include "nsIDateTimeFormat.h"
#include "nsDateTimeFormatCID.h"

char *date = MimeHeaders_get(headers, HEADER_DATE, false, true);   // "Tue, 27 May 2014 09:38:27 +0800"

  nsresult rv = NS_OK;
      nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
      if (!mDateFormatter)
      {
      mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
     }
      nsCAutoString convertedDateString;
      PRExplodedTime explodedMsgTime;
     
     rv = static_cast<nsresult>(PR_ParseTimeStringToExplodedTime(date, false, &explodedMsgTime));
     PRExplodedTime explodedCompTime;
     PR_ExplodeTime(PR_ImplodeTime(&explodedMsgTime), PR_LocalTimeParameters, &explodedCompTime);

     nsAutoString formattedDateString;
     if (NS_SUCCEEDED(rv))
     {
      rv = mDateFormatter->FormatPRExplodedTime(nullptr /* nsILocale* locale */,
                                                kDateFormatShort,
                                                kTimeFormatNoSeconds,
                                                &explodedCompTime,
                                                formattedDateString);  //formattedDateString = 2014-5-27 9:38

      if (NS_SUCCEEDED(rv))
        {
          CopyUTF16toUTF8(formattedDateString, convertedDateString);
           char *result = 0;
            result = (char *) PR_MALLOC(100);
             memcpy(result, convertedDateString.get(), convertedDateString.Length());
         result[convertedDateString.Length()] = 0;
          mime_intl_insert_message_header_1(&newBody, &result, HEADER_DATE,
                        MimeGetNamedString(MIME_MHTML_DATE),
                        mailcharset, htmlEdit);
        }
        else
        {
          mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE,
                        MimeGetNamedString(MIME_MHTML_DATE),
                        mailcharset, htmlEdit);
        }
      }
回复 支持 反对

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
6#
 楼主| 发表于 2016-4-20 23:35:37 | 只看该作者
D:\svn\Client\ThinkMail_ClientWin_2013\trunk\src\thinkmail\mailnews\extensions\mdn\src\nsMsgMdnGenerator.cpp
char opertorTime[50] = {0};  // "Tue, 27 May 2014 09:38:27 +0800"
PR_FormatTimeUSEnglish(opertorTime, 50,
                "Date: %a, %d %b %Y %H:%M:%S ",
                &now);
        PR_snprintf(opertorTime + strlen(opertorTime), 50,
                "%c%02d%02d" CRLF,
                (gmtoffset >= 0 ? '+' : '-'),
                ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) / 60),
                ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) % 60));

nsresult rv2 = NS_OK;
        nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
        if (!mDateFormatter)
        {
                mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
        }
        nsCAutoString convertedDateString;
        PRExplodedTime explodedMsgTime;

        rv2 = static_cast<nsresult>(PR_ParseTimeStringToExplodedTime(opertorTime, false, &explodedMsgTime));
        PRExplodedTime explodedCompTime;
        PR_ExplodeTime(PR_ImplodeTime(&explodedMsgTime), PR_LocalTimeParameters, &explodedCompTime);

        nsAutoString formattedDateString;
        if (NS_SUCCEEDED(rv2))
        {
                rv = mDateFormatter->FormatPRExplodedTime(nullptr /* nsILocale* locale */,
                        kDateFormatShort,
                        kTimeFormatSeconds,
                        &explodedCompTime,
                        formattedDateString);  //formattedDateString = 2014-5-27 9:38:27
        }
        firstPart1.AppendLiteral(CRLF);
        firstPart1.Append(formattedDateString);
        ///////////////

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-5 23:52 , Processed in 0.166791 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表