+static int pop_parse_path(const char *path, ACCOUNT *act)
+{
+ ciss_url_t url;
+ char s[BUFSIZ];
+
+ /* Defaults */
+ act->flags = 0;
+ act->port = POP3_PORT;
+ act->type = M_ACCT_TYPE_POP;
+ m_strcpy(s, sizeof(s), path);
+ url_parse_ciss(&url, s);
+
+ if (url.scheme == U_POP || url.scheme == U_POPS) {
+ if (url.scheme == U_POPS) {
+ act->has_ssl = 1;
+ act->port = POP3S_PORT;
+ }
+
+ if (m_strisempty(url.path) && !mutt_account_fromurl(act, &url))
+ return 0;
+ }
+
+ return -1;
+}
+
+static pop_data_t *pop_find_conn(ACCOUNT *act)
+{
+ pop_data_t *pd = NULL;
+
+ for (int i = 0; i < conns.len; i++) {
+ if (mutt_account_match(act, &conns.arr[i]->act)) {
+ pd = pop_data_dup(conns.arr[i]);
+ break;
+ }
+ }
+ if (!pd) {
+ pd = pop_data_new();
+ pd->act = *act;
+ }
+
+ return pd;
+}
+
+static int pop_open_mailbox(CONTEXT *ctx)
+{
+ char buf[BUFSIZ];
+ ACCOUNT act;
+ ciss_url_t url;
+ pop_data_t *pd = NULL;
+
+ if (pop_parse_path(ctx->path, &act)) {
+ mutt_error(_("%s is an invalid POP path"), ctx->path);
+ mutt_sleep(2);
+ return -1;
+ }
+
+ p_clear(&url, 1);
+ mutt_account_tourl(&act, &url);
+
+ el_lock();
+ pd = pop_find_conn(&act);
+ if (false) {
+ ctx->data = pd;
+ url_ciss_tostring(&url, buf, sizeof (buf), 0);
+ m_strreplace(&ctx->path, buf);
+ } else {
+ pop_data_delete(&pd);
+ }
+ el_unlock();
+
+ return -1;
+}
+