📄 rfc5092.txt
字号:
/* enough bits for a UTF-16 character? */ if (bitcount >= 16) { bitcount -= 16; utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; /* convert UTF16 to UCS4 */ if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; continue; } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { ucs4 += utf16 - UTF16LOSTART + UTF16BASE; } else {Melnikov & Newman Standards Track [Page 26]RFC 5092 IMAP URL Scheme November 2007 ucs4 = utf16; } /* convert UTF-16 range of UCS4 to UTF-8 */ if (ucs4 <= 0x7fUL) { utf8[0] = (unsigned char) ucs4; i = 1; } else if (ucs4 <= 0x7ffUL) { utf8[0] = 0xc0 | (unsigned char) (ucs4 >> 6); utf8[1] = 0x80 | (unsigned char) (ucs4 & 0x3f); i = 2; } else if (ucs4 <= 0xffffUL) { utf8[0] = 0xe0 | (unsigned char) (ucs4 >> 12); utf8[1] = 0x80 | (unsigned char) ((ucs4 >> 6) & 0x3f); utf8[2] = 0x80 | (unsigned char) (ucs4 & 0x3f); i = 3; } else { utf8[0] = 0xf0 | (unsigned char) (ucs4 >> 18); utf8[1] = 0x80 | (unsigned char) ((ucs4 >> 12) & 0x3f); utf8[2] = 0x80 | (unsigned char) ((ucs4 >> 6) & 0x3f); utf8[3] = 0x80 | (unsigned char) (ucs4 & 0x3f); i = 4; } /* convert utf8 to hex */ for (c = 0; c < i; ++c) { dst[0] = '%'; dst[1] = hex[utf8[c] >> 4]; dst[2] = hex[utf8[c] & 0x0f]; dst += 3; } } } /* skip over trailing '-' in modified UTF-7 encoding */ if (*src == '-') ++src; } } /* terminate destination string */ *dst = '\0';}/* Convert hex coded UTF-8 URL path to modified UTF-7 IMAP mailbox * dst should be about twice the length of src to deal with non-hex * coded URLs */int URLtoMailbox(char *dst, char *src){ unsigned int utf8pos = 0; unsigned int utf8total, i, c, utf7mode, bitstogo, utf16flag; unsigned long ucs4 = 0, bitbuf = 0;Melnikov & Newman Standards Track [Page 27]RFC 5092 IMAP URL Scheme November 2007 utf7mode = 0; /* is the output UTF7 currently in base64 mode? */ utf8total = 0; /* how many octets is the current input UTF-8 char; 0 == between characters */ bitstogo = 0; /* bits that need to be encoded into base64; if bitstogo != 0 then utf7mode == 1 */ while ((c = (unsigned char)*src) != '\0') { ++src; /* undo hex-encoding */ if (c == '%' && src[0] != '\0' && src[1] != '\0') { c = HEXCHAR(src[0]); i = HEXCHAR(src[1]); if (c == XX || i == XX) { return 0; } else { c = (char)((c << 4) | i); } src += 2; } /* normal character? */ if (c >= ' ' && c <= '~') { /* switch out of UTF-7 mode */ if (utf7mode) { if (bitstogo) { *dst++ = base64chars[(bitbuf << (6 - bitstogo)) & 0x3F]; } *dst++ = '-'; utf7mode = 0; bitstogo = bitbuf = 0; } *dst++ = c; /* encode '&' as '&-' */ if (c == '&') { *dst++ = '-'; } continue; } /* switch to UTF-7 mode */ if (!utf7mode) { *dst++ = '&'; utf7mode = 1; } /* Encode US-ASCII characters as themselves */ if (c < 0x80) { ucs4 = c; utf8total = 1; } else if (utf8total) { /* this is a subsequent octet of a multi-octet character */ /* save UTF8 bits into UCS4 */Melnikov & Newman Standards Track [Page 28]RFC 5092 IMAP URL Scheme November 2007 ucs4 = (ucs4 << 6) | (c & 0x3FUL); if (++utf8pos < utf8total) { continue; } } else { /* this is the first octet of a multi-octet character */ utf8pos = 1; if (c < 0xE0) { utf8total = 2; ucs4 = c & 0x1F; } else if (c < 0xF0) { utf8total = 3; ucs4 = c & 0x0F; } else { /* NOTE: can't convert UTF8 sequences longer than 4 */ utf8total = 4; ucs4 = c & 0x03; } continue; } /* Finished with UTF-8 character. Make sure it isn't an overlong sequence. If it is, return failure. */ if ((ucs4 < 0x80 && utf8total > 1) || (ucs4 < 0x0800 && utf8total > 2) || (ucs4 < 0x00010000 && utf8total > 3) || (ucs4 < 0x00200000 && utf8total > 4) || (ucs4 < 0x04000000 && utf8total > 5) || (ucs4 < 0x80000000 && utf8total > 6)) { return 0; } /* loop to split ucs4 into two utf16 chars if necessary */ utf8total = 0; do { if (ucs4 >= UTF16BASE) { ucs4 -= UTF16BASE; bitbuf = (bitbuf << 16) | ((ucs4 >> UTF16SHIFT) + UTF16HIGHSTART); ucs4 = (ucs4 & UTF16MASK) + UTF16LOSTART; utf16flag = 1; } else { bitbuf = (bitbuf << 16) | ucs4; utf16flag = 0; } bitstogo += 16; /* spew out base64 */ while (bitstogo >= 6) { bitstogo -= 6; *dst++ = base64chars[(bitstogo ? (bitbuf >> bitstogo)Melnikov & Newman Standards Track [Page 29]RFC 5092 IMAP URL Scheme November 2007 : bitbuf) & 0x3F]; } } while (utf16flag); } /* if in UTF-7 mode, finish in ASCII */ if (utf7mode) { if (bitstogo) { *dst++ = base64chars[(bitbuf << (6 - bitstogo)) & 0x3F]; } *dst++ = '-'; } /* tie off string */ *dst = '\0'; return 1;}Appendix B. List of Changes since RFC 2192 Updated boilerplate, list of editor's, etc. Updated references. Updated ABNF not to use _, to use SP instead of SPACE, etc. Updated example domains to use example.org. Fixed ABNF error in "imessagelist" non-terminal. Updated ABNF, due to changes in RFC 3501, RFC 4466, and RFC 3986. Renamed "iuserauth" non-terminal to <iuserinfo>. Clarified that the userinfo component describes both authorization identity and mailbox naming scope. Allow for non-synchronizing literals in "enc-search". Added "ipartial" specifier that denotes a partial FETCH. Moved URLAUTH text from RFC 4467 to this document. Updated ABNF for the whole server to allow missing trailing "/" (e.g., "imap://imap.example.com" is now valid and is the same as "imap://imap.example.com/"). Clarified how relative-path references are constructed. Added more examples demonstrating relative-path references. Added rules for relative URLs and restructured ABNF as the result. Removed text on use of relative URLs in MHTML. Added examples demonstrating security considerations when resolving URLs. Recommend usage of STARTTLS/SASL security layer to protect confidential data. Removed some advices about connection reuse that were incorrect. Removed URLs referencing a list of mailboxes, as this feature hasn't seen any deployments. Clarified that user name "anonymous" is case-insensitive.Melnikov & Newman Standards Track [Page 30]RFC 5092 IMAP URL Scheme November 2007Appendix C. List of Changes since RFC 4467 Renamed <mechanism> to <uauth-mechanism>. Restructured ABNF.Appendix D. Acknowledgments Text describing URLAUTH was lifted from [URLAUTH] by Mark Crispin. Stephane H. Maes contributed some ideas to this document; he also co-edited early versions of this document. The editors would like to thank Mark Crispin, Ken Murchison, Ted Hardie, Zoltan Ordogh, Dave Cridland, Kjetil Torgrim Homme, Lisa Dusseault, Spencer Dawkins, Filip Navara, Shawn M. Emery, Sam Hartman, Russ Housley, and Lars Eggert for the time they devoted to reviewing this document and/or for the comments received.Authors' Addresses Chris Newman (Author/Editor) Sun Microsystems 3401 Centrelake Dr., Suite 410 Ontario, CA 91761 EMail: chris.newman@sun.com Alexey Melnikov (Editor) Isode Limited 5 Castle Business Village 36 Station Road Hampton, Middlesex TW12 2BX, UK EMail: Alexey.Melnikov@isode.com URI: http://www.melnikov.ca/Melnikov & Newman Standards Track [Page 31]RFC 5092 IMAP URL Scheme November 2007Full Copyright Statement Copyright (C) The IETF Trust (2007). This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights. This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.Intellectual Property The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79. Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr. The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org.Melnikov & Newman Standards Track [Page 32]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -