Skip to content

Commit fb7aae4

Browse files
committed
NET-614 IMAP fails to quote/encode mailbox names
More commands with mailbox name parameters git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/trunk@1842972 13f79535-47bb-0310-9956-ffa450edef68
1 parent 51bf45a commit fb7aae4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/main/java/org/apache/commons/net/imap/IMAP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ protected String generateCommandID()
480480
* @param input the value to be quoted, may be null
481481
* @return the quoted value
482482
*/
483-
static String quoteString(String input) {
483+
static String quoteMailboxName(String input) {
484484
if (input == null) { // Don't throw NPE here
485485
return null;
486486
}

src/main/java/org/apache/commons/net/imap/IMAPClient.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public boolean login(String username, String password) throws IOException
112112
*/
113113
public boolean select(String mailboxName) throws IOException
114114
{
115-
return doCommand (IMAPCommand.SELECT, mailboxName);
115+
return doCommand (IMAPCommand.SELECT, quoteMailboxName(mailboxName));
116116
}
117117

118118
/**
@@ -123,7 +123,7 @@ public boolean select(String mailboxName) throws IOException
123123
*/
124124
public boolean examine(String mailboxName) throws IOException
125125
{
126-
return doCommand (IMAPCommand.EXAMINE, mailboxName);
126+
return doCommand (IMAPCommand.EXAMINE, quoteMailboxName(mailboxName));
127127
}
128128

129129
/**
@@ -134,7 +134,7 @@ public boolean examine(String mailboxName) throws IOException
134134
*/
135135
public boolean create(String mailboxName) throws IOException
136136
{
137-
return doCommand (IMAPCommand.CREATE, mailboxName);
137+
return doCommand (IMAPCommand.CREATE, quoteMailboxName(mailboxName));
138138
}
139139

140140
/**
@@ -145,7 +145,7 @@ public boolean create(String mailboxName) throws IOException
145145
*/
146146
public boolean delete(String mailboxName) throws IOException
147147
{
148-
return doCommand (IMAPCommand.DELETE, mailboxName);
148+
return doCommand (IMAPCommand.DELETE, quoteMailboxName(mailboxName));
149149
}
150150

151151
/**
@@ -157,7 +157,7 @@ public boolean delete(String mailboxName) throws IOException
157157
*/
158158
public boolean rename(String oldMailboxName, String newMailboxName) throws IOException
159159
{
160-
return doCommand (IMAPCommand.RENAME, oldMailboxName + " " + newMailboxName);
160+
return doCommand (IMAPCommand.RENAME, quoteMailboxName(oldMailboxName) + " " + quoteMailboxName(newMailboxName));
161161
}
162162

163163
/**
@@ -168,7 +168,7 @@ public boolean rename(String oldMailboxName, String newMailboxName) throws IOExc
168168
*/
169169
public boolean subscribe(String mailboxName) throws IOException
170170
{
171-
return doCommand (IMAPCommand.SUBSCRIBE, mailboxName);
171+
return doCommand (IMAPCommand.SUBSCRIBE, quoteMailboxName(mailboxName));
172172
}
173173

174174
/**
@@ -179,7 +179,7 @@ public boolean subscribe(String mailboxName) throws IOException
179179
*/
180180
public boolean unsubscribe(String mailboxName) throws IOException
181181
{
182-
return doCommand (IMAPCommand.UNSUBSCRIBE, mailboxName);
182+
return doCommand (IMAPCommand.UNSUBSCRIBE, quoteMailboxName(mailboxName));
183183
}
184184

185185
/**
@@ -196,7 +196,7 @@ public boolean unsubscribe(String mailboxName) throws IOException
196196
*/
197197
public boolean list(String refName, String mailboxName) throws IOException
198198
{
199-
return doCommand (IMAPCommand.LIST, quoteString(refName) + " " + quoteString(mailboxName));
199+
return doCommand (IMAPCommand.LIST, quoteMailboxName(refName) + " " + quoteMailboxName(mailboxName));
200200
}
201201

202202
/**
@@ -209,7 +209,7 @@ public boolean list(String refName, String mailboxName) throws IOException
209209
*/
210210
public boolean lsub(String refName, String mailboxName) throws IOException
211211
{
212-
return doCommand (IMAPCommand.LSUB, quoteString(refName) + " " + quoteString(mailboxName));
212+
return doCommand (IMAPCommand.LSUB, quoteMailboxName(refName) + " " + quoteMailboxName(mailboxName));
213213
}
214214

215215
/**
@@ -226,7 +226,7 @@ public boolean status(String mailboxName, String[] itemNames) throws IOException
226226
}
227227

228228
StringBuilder sb = new StringBuilder();
229-
sb.append(mailboxName);
229+
sb.append(quoteMailboxName(mailboxName));
230230

231231
sb.append(" (");
232232
for ( int i = 0; i < itemNames.length; i++ )
@@ -253,7 +253,7 @@ public boolean status(String mailboxName, String[] itemNames) throws IOException
253253
*/
254254
public boolean append(String mailboxName, String flags, String datetime, String message) throws IOException
255255
{
256-
StringBuilder args = new StringBuilder(mailboxName);
256+
StringBuilder args = new StringBuilder(quoteMailboxName(mailboxName));
257257
if (flags != null) {
258258
args.append(" ").append(flags);
259259
}
@@ -417,7 +417,7 @@ public boolean store(String sequenceSet, String itemNames, String itemValues)
417417
*/
418418
public boolean copy(String sequenceSet, String mailboxName) throws IOException
419419
{
420-
return doCommand (IMAPCommand.COPY, sequenceSet + " " + mailboxName);
420+
return doCommand (IMAPCommand.COPY, sequenceSet + " " + quoteMailboxName(mailboxName));
421421
}
422422

423423
/**

0 commit comments

Comments
 (0)