本文整理汇总了C#中System.IO.StringReader.ReadWord方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.ReadWord方法的具体用法?C# StringReader.ReadWord怎么用?C# StringReader.ReadWord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.ReadWord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>KEYWORD (string)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>KEYWORD (string)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_Keyword Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"KEYWORD",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'KEYWORD' key.");
}
string value = r.ReadWord();
if(value == null){
throw new ParseException("Parse error: Invalid 'KEYWORD' value.");
}
return new IMAP_Search_Key_Keyword(value);
}
示例2: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>LARGER (string)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>LARGER (string)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_Larger Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"LARGER",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'LARGER' key.");
}
string value = r.ReadWord();
if(value == null){
throw new ParseException("Parse error: Invalid 'LARGER' value.");
}
int size = 0;
if(!int.TryParse(value,out size)){
throw new ParseException("Parse error: Invalid 'LARGER' value.");
}
return new IMAP_Search_Key_Larger(size);
}
示例3: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>DRAFT</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>DRAFT</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_Draft Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"DRAFT",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'DRAFT' key.");
}
return new IMAP_Search_Key_Draft();
}
示例4: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>SENTON (string)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>SENTON (string)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_SentOn Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"SENTON",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'SENTON' key.");
}
string value = r.ReadWord();
if(value == null){
throw new ParseException("Parse error: Invalid 'SENTON' value.");
}
DateTime date;
try{
date = IMAP_Utils.ParseDate(value);
}
catch{
throw new ParseException("Parse error: Invalid 'SENTON' value.");
}
return new IMAP_Search_Key_SentOn(date);
}
示例5: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>FROM (string)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>FROM (string)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_From Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"FROM",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'FROM' key.");
}
string value = IMAP_Utils.ReadString(r);
if(value == null){
throw new ParseException("Parse error: Invalid 'FROM' value.");
}
return new IMAP_Search_Key_From(value);
}
示例6: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>HEADER (field-name) (string)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>HEADER (field-name) (string)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_Header Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"HEADER",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'HEADER' key.");
}
string fieldName = IMAP_Utils.ReadString(r);
if(fieldName == null){
throw new ParseException("Parse error: Invalid 'HEADER' field-name value.");
}
string value = IMAP_Utils.ReadString(r);
if(value == null){
throw new ParseException("Parse error: Invalid 'HEADER' string value.");
}
return new IMAP_Search_Key_Header(fieldName,value);
}
示例7: Parse
/// <summary>
/// Returns parsed IMAP SEARCH <b>UID (sequence set)</b> key.
/// </summary>
/// <param name="r">String reader.</param>
/// <returns>Returns parsed IMAP SEARCH <b>UID (sequence set)</b> key.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception>
/// <exception cref="ParseException">Is raised when parsing fails.</exception>
internal static IMAP_Search_Key_Uid Parse(StringReader r)
{
if(r == null){
throw new ArgumentNullException("r");
}
string word = r.ReadWord();
if(!string.Equals(word,"UID",StringComparison.InvariantCultureIgnoreCase)){
throw new ParseException("Parse error: Not a SEARCH 'UID' key.");
}
r.ReadToFirstChar();
string value = r.QuotedReadToDelimiter(' ');
if(value == null){
throw new ParseException("Parse error: Invalid 'UID' value.");
}
try{
return new IMAP_Search_Key_Uid(IMAP_t_SeqSet.Parse(value));
}
catch{
throw new ParseException("Parse error: Invalid 'UID' value.");
}
}
示例8: SEARCH
//.........这里部分代码省略.........
structure's TO field.
UID <sequence set>
Messages with unique identifiers corresponding to the specified
unique identifier set. Sequence set ranges are permitted.
UNANSWERED
Messages that do not have the \Answered flag set.
UNDELETED
Messages that do not have the \Deleted flag set.
UNDRAFT
Messages that do not have the \Draft flag set.
UNFLAGGED
Messages that do not have the \Flagged flag set.
UNKEYWORD <flag>
Messages that do not have the specified keyword flag set.
UNSEEN
Messages that do not have the \Seen flag set.
Example: C: A282 SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM "Smith"
S: * SEARCH 2 84 882
S: A282 OK SEARCH completed
C: A283 SEARCH TEXT "string not in mailbox"
S: * SEARCH
S: A283 OK SEARCH completed
C: A284 SEARCH CHARSET UTF-8 TEXT {6}
C: XXXXXX
S: * SEARCH 43
S: A284 OK SEARCH completed
*/
if(!this.IsAuthenticated){
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"NO","Authentication required."));
return;
}
if(m_pSelectedFolder == null){
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"NO","Error: This command is valid only in selected state."));
return;
}
// Store start time
long startTime = DateTime.Now.Ticks;
#region Parse arguments
_CmdReader cmdReader = new _CmdReader(this,cmdText,Encoding.UTF8);
cmdReader.Start();
StringReader r = new StringReader(cmdReader.CmdLine);
// See if we have optional CHARSET argument.
if(r.StartsWith("CHARSET",false)){
r.ReadWord();
string charset = r.ReadWord();
if(!(string.Equals(charset,"US-ASCII",StringComparison.InvariantCultureIgnoreCase) || string.Equals(charset,"UTF-8",StringComparison.InvariantCultureIgnoreCase))){
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"NO",new IMAP_t_orc_BadCharset(new string[]{"US-ASCII","UTF-8"}),"Not supported charset."));
return;
}
}
#endregion
try{
IMAP_Search_Key_Group criteria = IMAP_Search_Key_Group.Parse(r);
UpdateSelectedFolderAndSendChanges();
List<int> matchedValues = new List<int>();
IMAP_e_Search searchArgs = new IMAP_e_Search(criteria,new IMAP_r_ServerStatus(cmdTag,"OK","SEARCH completed in %exectime seconds."));
searchArgs.Matched += new EventHandler<EventArgs<long>>(delegate(object s,EventArgs<long> e){
if(uid){
matchedValues.Add((int)e.Value);
}
else{
// Search sequence-number for that message.
int seqNo = m_pSelectedFolder.GetSeqNo(e.Value);
if(seqNo != -1){
matchedValues.Add((int)e.Value);
}
}
});
OnSearch(searchArgs);
m_pResponseSender.SendResponseAsync(new IMAP_r_u_Search(matchedValues.ToArray()));
m_pResponseSender.SendResponseAsync(IMAP_r_ServerStatus.Parse(searchArgs.Response.ToString().TrimEnd().Replace("%exectime",((DateTime.Now.Ticks - startTime) / (decimal)10000000).ToString("f2"))));
}
catch{
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"BAD","Error in arguments."));
}
}
示例9: FETCH
//.........这里部分代码省略.........
catch{
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"BAD","Error in arguments: Invalid 'sequence-set' value."));
return;
}
#region Parse data-items
List<IMAP_t_Fetch_i> dataItems = new List<IMAP_t_Fetch_i>();
bool msgDataNeeded = false;
// Remove parenthesizes.
string dataItemsString = parts[1].Trim();
if(dataItemsString.StartsWith("(") && dataItemsString.EndsWith(")")){
dataItemsString = dataItemsString.Substring(1,dataItemsString.Length - 2).Trim();
}
// Replace macros.
dataItemsString = dataItemsString.Replace("ALL","FLAGS INTERNALDATE RFC822.SIZE ENVELOPE");
dataItemsString = dataItemsString.Replace("FAST","FLAGS INTERNALDATE RFC822.SIZE");
dataItemsString = dataItemsString.Replace("FULL","FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY");
StringReader r = new StringReader(dataItemsString);
IMAP_Fetch_DataType fetchDataType = IMAP_Fetch_DataType.MessageHeader;
// Parse data-items.
while(r.Available > 0){
r.ReadToFirstChar();
#region BODYSTRUCTURE
if(r.StartsWith("BODYSTRUCTURE",false)){
r.ReadWord();
dataItems.Add(new IMAP_t_Fetch_i_BodyStructure());
msgDataNeeded = true;
if(fetchDataType != IMAP_Fetch_DataType.FullMessage){
fetchDataType = IMAP_Fetch_DataType.MessageStructure;
}
}
#endregion
#region BODY[<section>]<<partial>> and BODY.PEEK[<section>]<<partial>>
else if(r.StartsWith("BODY[",false) || r.StartsWith("BODY.PEEK[",false)){
bool peek = r.StartsWith("BODY.PEEK[",false);
r.ReadWord();
#region Parse <section>
string section = r.ReadParenthesized();
// Full message wanted.
if(string.IsNullOrEmpty(section)){
fetchDataType = IMAP_Fetch_DataType.FullMessage;
}
else{
// Left-side part-items must be numbers, only last one may be (HEADER,HEADER.FIELDS,HEADER.FIELDS.NOT,MIME,TEXT).
StringReader rSection = new StringReader(section);
string remainingSection = rSection.ReadWord();
while(remainingSection.Length > 0){
string[] section_parts = remainingSection.Split(new char[]{'.'},2);
// Not part number.
if(!Net_Utils.IsInteger(section_parts[0])){
示例10: APPEND
private void APPEND(string cmdTag,string cmdText)
{
/* RFC 3501 6.3.11. APPEND Command.
Arguments: mailbox name
OPTIONAL flag parenthesized list
OPTIONAL date/time string
message literal
Responses: no specific responses for this command
Result: OK - append completed
NO - append error: can't append to that mailbox, error
in flags or date/time or message text
BAD - command unknown or arguments invalid
The APPEND command appends the literal argument as a new message
to the end of the specified destination mailbox. This argument
SHOULD be in the format of an [RFC-2822] message. 8-bit
characters are permitted in the message. A server implementation
that is unable to preserve 8-bit data properly MUST be able to
reversibly convert 8-bit APPEND data to 7-bit using a [MIME-IMB]
content transfer encoding.
Note: There MAY be exceptions, e.g., draft messages, in
which required [RFC-2822] header lines are omitted in
the message literal argument to APPEND. The full
implications of doing so MUST be understood and
carefully weighed.
If a flag parenthesized list is specified, the flags SHOULD be set
in the resulting message; otherwise, the flag list of the
resulting message is set to empty by default. In either case, the
Recent flag is also set.
If a date-time is specified, the internal date SHOULD be set in
the resulting message; otherwise, the internal date of the
resulting message is set to the current date and time by default.
If the append is unsuccessful for any reason, the mailbox MUST be
restored to its state before the APPEND attempt; no partial
appending is permitted.
If the destination mailbox does not exist, a server MUST return an
error, and MUST NOT automatically create the mailbox. Unless it
is certain that the destination mailbox can not be created, the
server MUST send the response code "[TRYCREATE]" as the prefix of
the text of the tagged NO response. This gives a hint to the
client that it can attempt a CREATE command and retry the APPEND
if the CREATE is successful.
If the mailbox is currently selected, the normal new message
actions SHOULD occur. Specifically, the server SHOULD notify the
client immediately via an untagged EXISTS response. If the server
does not do so, the client MAY issue a NOOP command (or failing
that, a CHECK command) after one or more APPEND commands.
Example: C: A003 APPEND saved-messages (\Seen) {310}
S: + Ready for literal data
C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
C: From: Fred Foobar <[email protected]>
C: Subject: afternoon meeting
C: To: [email protected]
C: Message-Id: <[email protected]>
C: MIME-Version: 1.0
C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
C:
C: Hello Joe, do you think we can meet at 3:30 tomorrow?
C:
S: A003 OK APPEND completed
Note: The APPEND command is not used for message delivery,
because it does not provide a mechanism to transfer [SMTP]
envelope information.
*/
if(!this.IsAuthenticated){
m_pResponseSender.SendResponseAsync(new IMAP_r_ServerStatus(cmdTag,"NO","Authentication required."));
return;
}
// Store start time
long startTime = DateTime.Now.Ticks;
#region Parse arguments
StringReader r = new StringReader(cmdText);
r.ReadToFirstChar();
string folder = null;
if(r.StartsWith("\"")){
folder = IMAP_Utils.DecodeMailbox(r.ReadWord());
}
else{
folder = IMAP_Utils.DecodeMailbox(r.QuotedReadToDelimiter(' '));
}
r.ReadToFirstChar();
List<string> flags = new List<string>();
if(r.StartsWith("(")){
foreach(string f in r.ReadParenthesized().Split(' ')){
if(f.Length > 0 && !flags.Contains(f.Substring(1))){
//.........这里部分代码省略.........
示例11: ReadString
/// <summary>
/// Reads IMAP string/astring/nstring/utf8-quoted from string reader.
/// </summary>
/// <param name="reader">String reader.</param>
/// <returns>Returns IMAP string.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>reader</b> is null reference.</exception>
internal static string ReadString(StringReader reader)
{
if(reader == null){
throw new ArgumentNullException("reader");
}
reader.ReadToFirstChar();
// utf8-quoted
if(reader.StartsWith("*\"")){
reader.ReadSpecifiedLength(1);
return reader.ReadWord();
}
// string/astring/nstring
else{
string word = reader.ReadWord();
// nstring
if(string.Equals(word,"NIL",StringComparison.InvariantCultureIgnoreCase)){
return null;
}
return word;
}
}
示例12: ReadData
/// <summary>
/// Reads IMAP string(string-literal,quoted-string,NIL) and remaining FETCH line if needed.
/// </summary>
/// <param name="imap">IMAP client.</param>
/// <param name="r">Fetch line reader.</param>
/// <param name="callback">Fetch completion callback.</param>
/// <param name="stream">Stream where to store readed data.</param>
/// <returns>Returns true if completed asynchronously or false if completed synchronously.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>imap</b>,<b>r</b>,<b>callback</b> or <b>stream</b> is null reference.</exception>
private bool ReadData(IMAP_Client imap,StringReader r,EventHandler<EventArgs<Exception>> callback,Stream stream)
{
if(imap == null){
throw new ArgumentNullException("imap");
}
if(r == null){
throw new ArgumentNullException("r");
}
if(callback == null){
throw new ArgumentNullException("callback");
}
if(stream == null){
throw new ArgumentNullException("stream");
}
r.ReadToFirstChar();
// We don't have data.
if(r.StartsWith("NIL",false)){
// Eat NIL.
r.ReadWord();
return false;
}
// Data value is returned as string-literal.
else if(r.StartsWith("{",false)){
IMAP_Client.ReadStringLiteralAsyncOP op = new IMAP_Client.ReadStringLiteralAsyncOP(stream,Convert.ToInt32(r.ReadParenthesized()));
op.CompletedAsync += delegate(object sender,EventArgs<IMAP_Client.ReadStringLiteralAsyncOP> e){
try{
// Read string literal failed.
if(op.Error != null){
callback(this,new EventArgs<Exception>(op.Error));
}
else{
// Read next fetch line completed synchronously.
if(!ReadNextFetchLine(imap,r,callback)){
ParseDataItems(imap,r,callback);
}
}
}
catch(Exception x){
callback(this,new EventArgs<Exception>(x));
}
finally{
op.Dispose();
}
};
// Read string literal completed sync.
if(!imap.ReadStringLiteralAsync(op)){
try{
// Read string literal failed.
if(op.Error != null){
callback(this,new EventArgs<Exception>(op.Error));
return true;
}
else{
// Read next fetch line completed synchronously.
if(!ReadNextFetchLine(imap,r,callback)){
return false;
}
else{
return true;
}
}
}
finally{
op.Dispose();
}
}
// Read string literal completed async.
else{
return true;
}
}
// Data is quoted-string.
else{
byte[] data = Encoding.UTF8.GetBytes(r.ReadWord());
stream.Write(data,0,data.Length);
return false;
}
}
示例13: ParseDataItems
/// <summary>
/// Starts parsing fetch data-items,
/// </summary>
/// <param name="imap">IMAP client.</param>
/// <param name="r">Fetch line reader.</param>
/// <param name="callback">Callback to be called when parsing completes.</param>
/// <exception cref="ArgumentNullException">Is raised when <b>imap</b>,<b>r</b> or <b>callback</b> is null reference.</exception>
private void ParseDataItems(IMAP_Client imap,StringReader r,EventHandler<EventArgs<Exception>> callback)
{
if(imap == null){
throw new ArgumentNullException("imap");
}
if(r == null){
throw new ArgumentNullException("r");
}
if(callback == null){
throw new ArgumentNullException("callback");
}
/* RFC 3501 7.4.2. FETCH Response.
Example: S: * 23 FETCH (FLAGS (\Seen) RFC822.SIZE 44827)
*/
while(true){
r.ReadToFirstChar();
#region BODY[]
if(r.StartsWith("BODY[",false)){
/* RFC 3501 7.4.2. FETCH Response.
BODY[<section>]<<origin octet>>
A string expressing the body contents of the specified section.
The string SHOULD be interpreted by the client according to the
content transfer encoding, body type, and subtype.
If the origin octet is specified, this string is a substring of
the entire body contents, starting at that origin octet. This
means that BODY[]<0> MAY be truncated, but BODY[] is NEVER
truncated.
Note: The origin octet facility MUST NOT be used by a server
in a FETCH response unless the client specifically requested
it by means of a FETCH of a BODY[<section>]<<partial>> data
item.
8-bit textual data is permitted if a [CHARSET] identifier is
part of the body parameter parenthesized list for this section.
Note that headers (part specifiers HEADER or MIME, or the
header portion of a MESSAGE/RFC822 part), MUST be 7-bit; 8-bit
characters are not permitted in headers. Note also that the
[RFC-2822] delimiting blank line between the header and the
body is not affected by header line subsetting; the blank line
is always included as part of header data, except in the case
of a message which has no body and no blank line.
Non-textual data such as binary data MUST be transfer encoded
into a textual form, such as BASE64, prior to being sent to the
client. To derive the original binary data, the client MUST
decode the transfer encoded string.
*/
// Eat BODY word.
r.ReadWord();
// Read body-section.
string section = r.ReadParenthesized();
// Read origin if any.
int offset = -1;
if(r.StartsWith("<")){
offset = Convert.ToInt32(r.ReadParenthesized().Split(' ')[0]);
}
IMAP_t_Fetch_r_i_Body dataItem = new IMAP_t_Fetch_r_i_Body(section,offset,new MemoryStreamEx(32000));
m_pDataItems.Add(dataItem);
// Raise event, allow user to specify store stream.
IMAP_Client_e_FetchGetStoreStream eArgs = new IMAP_Client_e_FetchGetStoreStream(this,dataItem);
imap.OnFetchGetStoreStream(eArgs);
// User specified own stream, use it.
if(eArgs.Stream != null){
dataItem.Stream.Dispose();
dataItem.SetStream(eArgs.Stream);
}
// Read data will complete async and will continue data-items parsing, exit this method.
if(ReadData(imap,r,callback,dataItem.Stream)){
return;
}
// Continue processing.
//else{
}
#endregion
#region BODY
else if(r.StartsWith("BODY ",false)){
//IMAP_t_Fetch_r_i_BodyS
}
//.........这里部分代码省略.........
示例14: GetList
//.........这里部分代码省略.........
if(!response[0].StartsWith("1")){
throw new FTP_ClientException(response[0]);
}
MemoryStream ms = new MemoryStream();
m_pDataConnection.ReadAll(ms);
response = ReadResponse();
if(!response[0].StartsWith("2")){
throw new FTP_ClientException(response[0]);
}
ms.Position = 0;
SmartStream listStream = new SmartStream(ms,true);
string[] winDateFormats = new string[]{"M-d-yy h:mmtt"};
string[] unixFormats = new string[]{"MMM d H:mm","MMM d yyyy"};
SmartStream.ReadLineAsyncOP args = new SmartStream.ReadLineAsyncOP(new byte[8000],SizeExceededAction.JunkAndThrowException);
while(true){
listStream.ReadLine(args,false);
if(args.Error != null){
throw args.Error;
}
else if(args.BytesInBuffer == 0){
break;
}
string line = args.LineUtf8;
// Dedect listing.
string listingType = "unix";
if(line != null){
StringReader r = new StringReader(line);
DateTime modified;
if(DateTime.TryParseExact(r.ReadWord() + " " + r.ReadWord(),new string[]{"MM-dd-yy hh:mmtt"},System.Globalization.DateTimeFormatInfo.InvariantInfo,System.Globalization.DateTimeStyles.None,out modified)){
listingType = "win";
}
}
try{
// Windows listing.
if(listingType == "win"){
// MM-dd-yy hh:mm <DIR> directoryName
// MM-dd-yy hh:mm size fileName
StringReader r = new StringReader(line);
// Read date
DateTime modified = DateTime.ParseExact(r.ReadWord() + " " + r.ReadWord(),winDateFormats,System.Globalization.DateTimeFormatInfo.InvariantInfo,System.Globalization.DateTimeStyles.None);
r.ReadToFirstChar();
// We have directory.
if(r.StartsWith("<dir>",false)){
r.ReadSpecifiedLength(5);
r.ReadToFirstChar();
retVal.Add(new FTP_ListItem(r.ReadToEnd(),0,modified,true));
}
// We have file
else{
// Read file size
long size = Convert.ToInt64(r.ReadWord());
r.ReadToFirstChar();
retVal.Add(new FTP_ListItem(r.ReadToEnd(),size,modified,false));
}
}
// Unix listing
else{
// "d"directoryAtttributes xx xx xx 0 MMM d HH:mm/yyyy directoryName
// fileAtttributes xx xx xx fileSize MMM d HH:mm/yyyy fileName
StringReader r = new StringReader(line);
string attributes = r.ReadWord();
r.ReadWord();
r.ReadWord();
r.ReadWord();
long size = Convert.ToInt64(r.ReadWord());
DateTime modified = DateTime.ParseExact(r.ReadWord() + " " + r.ReadWord() + " " + r.ReadWord(),unixFormats,System.Globalization.DateTimeFormatInfo.InvariantInfo,System.Globalization.DateTimeStyles.None);
r.ReadToFirstChar();
string name = r.ReadToEnd();
if(name != "." && name != ".."){
if(attributes.StartsWith("d")){
retVal.Add(new FTP_ListItem(name,0,modified,true));
}
else{
retVal.Add(new FTP_ListItem(name,size,modified,false));
}
}
}
}
catch{
// Skip unknown entries.
}
}
}
#endregion
return retVal.ToArray();
}
示例15: GetFolderQuota
/// <summary>
/// Gets specified folder quota info. Throws Exception if server doesn't support QUOTA.
/// </summary>
/// <param name="folder">Folder name.</param>
/// <returns></returns>
public IMAP_Quota GetFolderQuota(string folder)
{
/* RFC 2087 4.3. GETQUOTAROOT Command
Arguments: mailbox name
Data: untagged responses: QUOTAROOT, QUOTA
Result: OK - getquota completed
NO - getquota error: no such mailbox, permission denied
BAD - command unknown or arguments invalid
The GETQUOTAROOT command takes the name of a mailbox and returns the
list of quota roots for the mailbox in an untagged QUOTAROOT
response. For each listed quota root, it also returns the quota
root's resource usage and limits in an untagged QUOTA response.
Example: C: A003 GETQUOTAROOT INBOX
S: * QUOTAROOT INBOX ""
S: * QUOTA "" (STORAGE 10 512)
S: A003 OK Getquota completed
*/
if(!m_Connected){
throw new Exception("You must connect first !");
}
if(!m_Authenticated){
throw new Exception("You must authenticate first !");
}
IMAP_Quota retVal = null;
m_pSocket.WriteLine("a1 GETQUOTAROOT \"" + Core.Encode_IMAP_UTF7_String(folder) + "\"");
// Must get lines with * and cmdTag + OK or cmdTag BAD/NO
string reply = m_pSocket.ReadLine();
if(reply.StartsWith("*")){
// Read multiline response
while(reply.StartsWith("*")){
// Get rid of *
reply = reply.Substring(1).Trim();
if(reply.ToUpper().StartsWith("QUOTAROOT")){
// Skip QUOTAROOT
}
else if(reply.ToUpper().StartsWith("QUOTA")){
StringReader r = new StringReader(reply);
// Skip QUOTA word
r.ReadWord();
string qoutaRootName = r.ReadWord();
long storage = -1;
long maxStorage = -1;
long messages = -1;
long maxMessages = -1;
string limits = r.ReadParenthesized();
r = new StringReader(limits);
while(r.Available > 0){
string limitName = r.ReadWord();
// STORAGE usedBytes maximumAllowedBytes
if(limitName.ToUpper() == "STORAGE"){
storage = Convert.ToInt64(r.ReadWord());
maxStorage = Convert.ToInt64(r.ReadWord());
}
// STORAGE messagesCount maximumAllowedMessages
else if(limitName.ToUpper() == "MESSAGE"){
messages = Convert.ToInt64(r.ReadWord());
maxMessages = Convert.ToInt64(r.ReadWord());
}
}
retVal = new IMAP_Quota(qoutaRootName,messages,maxMessages,storage,maxStorage);
}
reply = m_pSocket.ReadLine();
}
}
reply = reply.Substring(reply.IndexOf(" ")).Trim(); // Remove Cmd tag
if(!reply.ToUpper().StartsWith("OK")){
throw new Exception("Server returned:" + reply);
}
return retVal;
}