Skip to content

Commit 57a7b37

Browse files
committed
Added a FolderNotFoundException
1 parent ba1c531 commit 57a7b37

File tree

10 files changed

+264
-1
lines changed

10 files changed

+264
-1
lines changed

MailKit/FolderNotFoundException.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// FolderNotFoundException.cs
3+
//
4+
// Author: Jeffrey Stedfast <jeff@xamarin.com>
5+
//
6+
// Copyright (c) 2014 Jeffrey Stedfast
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
using System;
28+
using System.Runtime.Serialization;
29+
30+
namespace MailKit {
31+
/// <summary>
32+
/// The exception that is thrown when a folder could not be found.
33+
/// </summary>
34+
/// <remarks>
35+
/// This exception is thrown by <see cref="IFolder.GetSubfolder"/>.
36+
/// </remarks>
37+
[Serializable]
38+
public class FolderNotFoundException : Exception
39+
{
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
42+
/// </summary>
43+
/// <param name="info">The serialization info.</param>
44+
/// <param name="context">The streaming context.</param>
45+
/// <exception cref="System.ArgumentNullException">
46+
/// <paramref name="info"/> is <c>null</c>.
47+
/// </exception>
48+
protected FolderNotFoundException (SerializationInfo info, StreamingContext context) : base (info, context)
49+
{
50+
if (info == null)
51+
throw new ArgumentNullException ("info");
52+
53+
FolderName = info.GetString ("FolderName");
54+
}
55+
56+
/// <summary>
57+
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
58+
/// </summary>
59+
/// <param name="message">The error message.</param>
60+
/// <param name="folderName">The name of the folder.</param>
61+
/// <param name="innerException">The inner exception.</param>
62+
/// <exception cref="System.ArgumentNullException">
63+
/// <paramref name="folderName"/> is <c>null</c>.
64+
/// </exception>
65+
public FolderNotFoundException (string message, string folderName, Exception innerException) : base (message, innerException)
66+
{
67+
if (folderName == null)
68+
throw new ArgumentNullException ("folderName");
69+
70+
FolderName = folderName;
71+
}
72+
73+
/// <summary>
74+
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
75+
/// </summary>
76+
/// <param name="message">The error message.</param>
77+
/// <param name="folderName">The name of the folder.</param>
78+
/// <exception cref="System.ArgumentNullException">
79+
/// <paramref name="folderName"/> is <c>null</c>.
80+
/// </exception>
81+
public FolderNotFoundException (string message, string folderName) : base (message)
82+
{
83+
if (folderName == null)
84+
throw new ArgumentNullException ("folderName");
85+
86+
FolderName = folderName;
87+
}
88+
89+
/// <summary>
90+
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
91+
/// </summary>
92+
/// <param name="folderName">The name of the folder.</param>
93+
/// <exception cref="System.ArgumentNullException">
94+
/// <paramref name="folderName"/> is <c>null</c>.
95+
/// </exception>
96+
public FolderNotFoundException (string folderName) : base ("The requested folder could not be found.")
97+
{
98+
if (folderName == null)
99+
throw new ArgumentNullException ("folderName");
100+
101+
FolderName = folderName;
102+
}
103+
104+
/// <summary>
105+
/// Gets the name of the folder that could not be found.
106+
/// </summary>
107+
/// <value>The name of the folder.</value>
108+
public string FolderName {
109+
get; private set;
110+
}
111+
}
112+
}

MailKit/IFolder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ public interface IFolder : IEnumerable<MimeMessage>
255255
/// <returns>The subfolder.</returns>
256256
/// <param name="name">The name of the subfolder.</param>
257257
/// <param name="cancellationToken">The cancellation token.</param>
258+
/// <exception cref="FolderNotFoundException">
259+
/// The requested folder could not be found.
260+
/// </exception>
258261
IFolder GetSubfolder (string name, CancellationToken cancellationToken);
259262

260263
/// <summary>

MailKit/MailKit.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<Compile Include="FolderAttributes.cs" />
113113
<Compile Include="FolderNamespace.cs" />
114114
<Compile Include="FolderNamespaceCollection.cs" />
115+
<Compile Include="FolderNotFoundException.cs" />
115116
<Compile Include="FolderRenamedEventArgs.cs" />
116117
<Compile Include="IFolder.cs" />
117118
<Compile Include="IMessageService.cs" />

MailKit/MailKit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<Compile Include="FolderAttributes.cs" />
102102
<Compile Include="FolderNamespace.cs" />
103103
<Compile Include="FolderNamespaceCollection.cs" />
104+
<Compile Include="FolderNotFoundException.cs" />
104105
<Compile Include="FolderRenamedEventArgs.cs" />
105106
<Compile Include="IFolder.cs" />
106107
<Compile Include="IMessageService.cs" />

MailKit/MailKit.iOS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Compile Include="FolderAttributes.cs" />
106106
<Compile Include="FolderNamespace.cs" />
107107
<Compile Include="FolderNamespaceCollection.cs" />
108+
<Compile Include="FolderNotFoundException.cs" />
108109
<Compile Include="FolderRenamedEventArgs.cs" />
109110
<Compile Include="IFolder.cs" />
110111
<Compile Include="IMessageService.cs" />

MailKit/Net/Imap/ImapFolder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ public IEnumerable<IFolder> GetSubfolders (bool subscribedOnly, CancellationToke
935935
/// <exception cref="System.IO.IOException">
936936
/// An I/O error occurred.
937937
/// </exception>
938+
/// <exception cref="FolderNotFoundException">
939+
/// The requested folder could not be found.
940+
/// </exception>
938941
/// <exception cref="ImapProtocolException">
939942
/// The server's response contained unexpected tokens.
940943
/// </exception>
@@ -971,7 +974,10 @@ public IFolder GetSubfolder (string name, CancellationToken cancellationToken)
971974
if (ic.Result != ImapCommandResult.Ok)
972975
throw new ImapCommandException ("LIST", ic.Result);
973976

974-
return list.Count > 0 ? list[0] : null;
977+
if (list.Count == 0)
978+
throw new FolderNotFoundException (fullName);
979+
980+
return list[0];
975981
}
976982

977983
/// <summary>

docs/en/MailKit.Net.Imap/ImapFolder.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,9 @@
21242124
<exception cref="T:MailKit.Net.Imap.ImapCommandException">
21252125
The server replied with a NO or BAD response.
21262126
</exception>
2127+
<exception cref="T:MailKit.FolderNotFoundException">
2128+
The requested folder could not be found.
2129+
</exception>
21272130
</Docs>
21282131
</Member>
21292132
<Member MemberName="GetSubfolders">
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<Type Name="FolderNotFoundException" FullName="MailKit.FolderNotFoundException">
2+
<TypeSignature Language="C#" Value="public class FolderNotFoundException : Exception" />
3+
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable beforefieldinit FolderNotFoundException extends System.Exception" />
4+
<AssemblyInfo>
5+
<AssemblyName>MailKit</AssemblyName>
6+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
7+
</AssemblyInfo>
8+
<Base>
9+
<BaseTypeName>System.Exception</BaseTypeName>
10+
</Base>
11+
<Interfaces />
12+
<Docs>
13+
<summary>
14+
The exception that is thrown when a folder could not be found.
15+
</summary>
16+
<remarks>
17+
This exception is thrown by <see cref="M:MailKit.IFolder.GetSubfolder(System.String,System.Threading.CancellationToken)" />.
18+
</remarks>
19+
</Docs>
20+
<Members>
21+
<Member MemberName=".ctor">
22+
<MemberSignature Language="C#" Value="public FolderNotFoundException (string folderName);" />
23+
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string folderName) cil managed" />
24+
<MemberType>Constructor</MemberType>
25+
<AssemblyInfo>
26+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
27+
</AssemblyInfo>
28+
<Parameters>
29+
<Parameter Name="folderName" Type="System.String" />
30+
</Parameters>
31+
<Docs>
32+
<param name="folderName">The name of the folder.</param>
33+
<summary>
34+
Initializes a new instance of the <see cref="T:MailKit.FolderNotFoundException" /> class.
35+
</summary>
36+
<remarks>To be added.</remarks>
37+
<exception cref="T:System.ArgumentNullException">
38+
<paramref name="folderName" /> is <c>null</c>.
39+
</exception>
40+
</Docs>
41+
</Member>
42+
<Member MemberName=".ctor">
43+
<MemberSignature Language="C#" Value="protected FolderNotFoundException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);" />
44+
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor(class System.Runtime.Serialization.SerializationInfo info, valuetype System.Runtime.Serialization.StreamingContext context) cil managed" />
45+
<MemberType>Constructor</MemberType>
46+
<AssemblyInfo>
47+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
48+
</AssemblyInfo>
49+
<Parameters>
50+
<Parameter Name="info" Type="System.Runtime.Serialization.SerializationInfo" />
51+
<Parameter Name="context" Type="System.Runtime.Serialization.StreamingContext" />
52+
</Parameters>
53+
<Docs>
54+
<param name="info">The serialization info.</param>
55+
<param name="context">The streaming context.</param>
56+
<summary>
57+
Initializes a new instance of the <see cref="T:MailKit.FolderNotFoundException" /> class.
58+
</summary>
59+
<remarks>To be added.</remarks>
60+
<exception cref="T:System.ArgumentNullException">
61+
<paramref name="info" /> is <c>null</c>.
62+
</exception>
63+
</Docs>
64+
</Member>
65+
<Member MemberName=".ctor">
66+
<MemberSignature Language="C#" Value="public FolderNotFoundException (string message, string folderName);" />
67+
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string message, string folderName) cil managed" />
68+
<MemberType>Constructor</MemberType>
69+
<AssemblyInfo>
70+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
71+
</AssemblyInfo>
72+
<Parameters>
73+
<Parameter Name="message" Type="System.String" />
74+
<Parameter Name="folderName" Type="System.String" />
75+
</Parameters>
76+
<Docs>
77+
<param name="message">The error message.</param>
78+
<param name="folderName">The name of the folder.</param>
79+
<summary>
80+
Initializes a new instance of the <see cref="T:MailKit.FolderNotFoundException" /> class.
81+
</summary>
82+
<remarks>To be added.</remarks>
83+
<exception cref="T:System.ArgumentNullException">
84+
<paramref name="folderName" /> is <c>null</c>.
85+
</exception>
86+
</Docs>
87+
</Member>
88+
<Member MemberName=".ctor">
89+
<MemberSignature Language="C#" Value="public FolderNotFoundException (string message, string folderName, Exception innerException);" />
90+
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string message, string folderName, class System.Exception innerException) cil managed" />
91+
<MemberType>Constructor</MemberType>
92+
<AssemblyInfo>
93+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
94+
</AssemblyInfo>
95+
<Parameters>
96+
<Parameter Name="message" Type="System.String" />
97+
<Parameter Name="folderName" Type="System.String" />
98+
<Parameter Name="innerException" Type="System.Exception" />
99+
</Parameters>
100+
<Docs>
101+
<param name="message">The error message.</param>
102+
<param name="folderName">The name of the folder.</param>
103+
<param name="innerException">The inner exception.</param>
104+
<summary>
105+
Initializes a new instance of the <see cref="T:MailKit.FolderNotFoundException" /> class.
106+
</summary>
107+
<remarks>To be added.</remarks>
108+
<exception cref="T:System.ArgumentNullException">
109+
<paramref name="folderName" /> is <c>null</c>.
110+
</exception>
111+
</Docs>
112+
</Member>
113+
<Member MemberName="FolderName">
114+
<MemberSignature Language="C#" Value="public string FolderName { get; }" />
115+
<MemberSignature Language="ILAsm" Value=".property instance string FolderName" />
116+
<MemberType>Property</MemberType>
117+
<AssemblyInfo>
118+
<AssemblyVersion>0.3.0.0</AssemblyVersion>
119+
</AssemblyInfo>
120+
<ReturnValue>
121+
<ReturnType>System.String</ReturnType>
122+
</ReturnValue>
123+
<Docs>
124+
<summary>
125+
Gets the name of the folder that could not be found.
126+
</summary>
127+
<value>The name of the folder.</value>
128+
<remarks>To be added.</remarks>
129+
</Docs>
130+
</Member>
131+
</Members>
132+
</Type>

docs/en/MailKit/IFolder.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,9 @@
11171117
</summary>
11181118
<returns>The subfolder.</returns>
11191119
<remarks>To be added.</remarks>
1120+
<exception cref="T:MailKit.FolderNotFoundException">
1121+
The requested folder could not be found.
1122+
</exception>
11201123
</Docs>
11211124
</Member>
11221125
<Member MemberName="GetSubfolders">

docs/en/index.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Type Name="FolderAttributes" Kind="Enumeration" />
6161
<Type Name="FolderNamespace" Kind="Class" />
6262
<Type Name="FolderNamespaceCollection" Kind="Class" />
63+
<Type Name="FolderNotFoundException" Kind="Class" />
6364
<Type Name="FolderRenamedEventArgs" Kind="Class" />
6465
<Type Name="IFolder" Kind="Interface" />
6566
<Type Name="IMessageService" Kind="Interface" />

0 commit comments

Comments
 (0)