commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johnny Haugen Sørgård (JIRA) <j...@apache.org>
Subject [jira] [Commented] (NET-601) IMAPClient.select cannot select mailbox in some cases with æøå, spaces and sub-folders
Date Sun, 28 Aug 2016 14:13:20 GMT

    [ https://issues.apache.org/jira/browse/NET-601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15443518#comment-15443518
] 

Johnny Haugen Sørgård commented on NET-601:
-------------------------------------------

Sebb - Here's test-code

Comments: 
* the config is up and running, so it can be used for testing purposes.
* problematic folders have been created.
* In production BASE64MailboxEncoder and BASE64MailboxDecoder from javamail have been used
to encode and decode foldernames.
* The test routine:
  - logs on, 
  - gets the list of folders
  - tries to select some folders using the encoder
  - finally tries to select all the folders as returned from LIST


	public static void test(){
		// config
		String host = "munin02.prpr.no";
		String user = "tte";
		String password = "g6o623ds";
		// login
		AuthenticatingIMAPClient imapClient = new AuthenticatingIMAPClient(/*getProtocol(), */true);
	// implicit
		// listener -> System.out
		final PrintCommandListener listener = new PrintCommandListener(System.out, true) {
			@Override
			public void protocolReplyReceived(ProtocolCommandEvent event) {

				if (event.getReplyCode() != IMAPReply.PARTIAL){ // This is dealt with by the chunk listener
					super.protocolReplyReceived(event);
				}
			}
		};
		imapClient.addProtocolCommandListener(listener);
		try {
			imapClient.connect(host);
			// Try oauth = e.g. gmail 
			((AuthenticatingIMAPClient) imapClient).authenticate(AuthenticatingIMAPClient.AUTH_METHOD.PLAIN,
user, password);
		} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException
e) {
			out("Error.connect: " + e.getMessage());
			throw new RuntimeException("Could not connect to server. " + e.getMessage(), e);
		}
		// get Folders
		String[] folders = getFoldersAsArray(imapClient);

		// try selected folders
		testFolder(imapClient, "Backup log", true);				// ok
		testFolder(imapClient, "Møter", true);					// ok
		testFolder(imapClient, "Presis\\Bank2", true);			// ok
		testFolder(imapClient, "Presis\\Bodø Industri", true);
		testFolder(imapClient, "Presis\\Done", true);			// ok
		testFolder(imapClient, "Presis\\id filer", true);
		testFolder(imapClient, "Sendte elementer", true);		// ok
		
		// try all folders
		for(String folder: folders){
			testFolder(imapClient, folder, false);
		}
	}
	private static void testFolder(AuthenticatingIMAPClient imapClient, String folder, boolean
convertFoldername){
	// select folder
		try {
			String fName = convertFoldername ? BASE64MailboxEncoder.encode(folder) : folder.trim();
			if (((!fName.equals(folder)) || (fName.contains(" "))) && (!fName.startsWith("\""))
) {
				fName = "\"" + fName + "\"";
			}
			out("imapFoldername: " + folder + " -> " + fName);

			out(folder  + ": " + String.valueOf(imapClient.select(fName)));

		} catch (NumberFormatException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	private static String[] getFoldersAsArray(AuthenticatingIMAPClient imapClient) {
		String[] result = null;
		try {
				imapClient.sendCommand("LIST \"\" \"*\"");
				String[] folders = imapClient.getReplyStrings();
				List<String> folderList = new ArrayList<String>();
				boolean acceptNext = false;;
				for (int i = 0; i < folders.length; i++) {
					out(folders[i]);
					String line = folders[i];
					if (! acceptNext) {
						if (line.startsWith("* LIST")) {
							int delTo = line.indexOf("\"\\\\\"");	// domino format
							int delCount = 5;
							if (delTo == -1) {
								delTo = line.indexOf("\"/\"");		// microsoft format
								delCount = 4;
							}
							if (delTo > 0) {
								line = line.substring(delTo + delCount);
							} else {
							}
							if (line.startsWith("{") && (line.endsWith("}"))) {
								acceptNext = true;
								line = "";
							}
						} else if (line.indexOf("OK LIST") > 0) {
							line = "";
						}
					}
					if (! line.isEmpty()) {
//						line = BASE64MailboxDecoder.decode(line);
						folderList.add(line);
						acceptNext = false;
					}
				}
				result = folderList.toArray(new String[0]);
		} catch (IOException | RuntimeException e) {
			e.printStackTrace();
		}		
		return result;
	}


> IMAPClient.select cannot select mailbox in some cases with æøå, spaces and sub-folders
> --------------------------------------------------------------------------------------
>
>                 Key: NET-601
>                 URL: https://issues.apache.org/jira/browse/NET-601
>             Project: Commons Net
>          Issue Type: Bug
>          Components: IMAP
>    Affects Versions: 3.5
>         Environment: eclipse on ubuntu workstation and ibm domino server on ubuntu server.
Connecting to IMAP on an IBM Domino server.
>            Reporter: Johnny Haugen Sørgård
>
> Partial response from LIST:
> AAAB LIST  "" "*"
> * LIST (\HasNoChildren) "\\" "Backup log"
> * LIST (\Noinferiors \HasNoChildren) "\\" Inbox
> * LIST (\HasNoChildren) "\\" M&APg-ter
> * LIST (\HasChildren) "\\" Presis
> * LIST (\HasNoChildren) "\\" {24}
> Presis\Bod&APg- Industri
> * LIST (\HasNoChildren) "\\" {11}
> Presis\Done
> * LIST (\HasNoChildren) "\\" {15}
> Presis\id filer
> Trying to select Presis\Bodø Industri fails like this
> AAAB SELECT "Presis\Bod&APg- Industri"
> AAAB NO SELECT failure, cannot select mailbox: Folder not found in IMAP name space
> And trying to select Presis\id filer fails like this
> AAAB SELECT "Presis\id filer"
> AAAB NO SELECT failure, cannot select mailbox: Folder not found in IMAP name space
> So far it seems like select fails when folder has more than one:
> * none US-ASCII
> * space
> * sub-folder separator



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message