Skip to content

Commit

Permalink
remove IMAPOPT_FASTMAILSHARING
Browse files Browse the repository at this point in the history
See also cyrusimap#3205 (closed)
and cyrusimap#5035
  • Loading branch information
dilyanpalauzov committed Sep 24, 2024
1 parent 7074191 commit 61b0c1d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 84 deletions.
85 changes: 10 additions & 75 deletions imap/http_dav.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ HIDDEN int calcarddav_parse_path(const char *path,
char *p, *collection = NULL, *freeme = NULL;
size_t len;
int ret = 0;
static struct buf redirect_buf = BUF_INITIALIZER;

if (*tgt->path) return 0; /* Already parsed */

Expand Down Expand Up @@ -697,12 +696,7 @@ HIDDEN int calcarddav_parse_path(const char *path,

/* Check if we're in user space */
len = strcspn(p, "/");
/* zzzz is part of the FastMail sorting hack to make shared collections
* always appear later */
if (!strncmp(p, USER_COLLECTION_PREFIX, len) || !strncmp(p, "zzzz", len)) {
if (!strncmp(p, "zzzz", len))
tgt->flags |= TGT_USER_ZZZZ;

if (!strncmp(p, USER_COLLECTION_PREFIX, len)) {
/* Skip past user prefix (and any extra '/') */
for (p += len; p[1] == '/'; p++);
if (!*p || !*++p) return 0;
Expand Down Expand Up @@ -796,21 +790,6 @@ HIDDEN int calcarddav_parse_path(const char *path,

const char *mboxname = mbname_intname(mbname);

/* Check for FastMail legacy sharing URLs and redirect */
if (httpd_userid && !config_getswitch(IMAPOPT_FASTMAILSHARING) &&
tgt->flags != TGT_DAV_SHARED &&
!mboxname_userownsmailbox(httpd_userid, mboxname)) {
buf_reset(&redirect_buf);
buf_printf(&redirect_buf, "%s/%s/%s/%s%c%s",
tgt->namespace->prefix, USER_COLLECTION_PREFIX,
httpd_userid, tgt->userid, SHARED_COLLECTION_DELIM,
tgt->collection);
*resultstr = buf_cstring(&redirect_buf);

ret = HTTP_MOVED;
goto done;
}

if (tgt->mbentry) {
/* Just return the mboxname (MKCOL or COPY/MOVE destination) */
tgt->mbentry->name = xstrdup(mboxname);
Expand Down Expand Up @@ -4804,24 +4783,6 @@ static int meth_delete_collection(struct transaction_t *txn,
int ret = HTTP_NO_CONTENT, r = 0;
struct mailbox *mailbox = NULL;

/* if FastMail sharing, we need to remove ACLs */
if (config_getswitch(IMAPOPT_FASTMAILSHARING) &&
!mboxname_userownsmailbox(httpd_userid, txn->req_tgt.mbentry->name)) {
struct mboxlock *namespacelock = mboxname_usernamespacelock(txn->req_tgt.mbentry->name);
r = mboxlist_setacl(&httpd_namespace, txn->req_tgt.mbentry->name,
httpd_userid, /*rights*/NULL, /*isadmin*/1,
httpd_userid, httpd_authstate);
mboxname_release(&namespacelock);
if (r) {
syslog(LOG_ERR, "meth_delete(%s) failed to remove acl: %s",
txn->req_tgt.mbentry->name, error_message(r));
txn->error.desc = error_message(r);
return HTTP_SERVER_ERROR;
}
sync_checkpoint(txn->conn->pin);
return HTTP_OK;
}

/* Special case of deleting a shared collection */
if (txn->req_tgt.flags == TGT_DAV_SHARED) {
char *inboxname = mboxname_user_mbox(txn->req_tgt.userid, NULL);
Expand Down Expand Up @@ -5886,7 +5847,7 @@ static int propfind_by_resources(struct propfind_ctx *fctx)
}


HIDDEN size_t make_collection_url(struct buf *buf, const char *urlprefix, int haszzzz,
HIDDEN size_t make_collection_url(struct buf *buf, const char *urlprefix,
const mbname_t *mbname, const char *userid)
{
buf_reset(buf);
Expand All @@ -5896,22 +5857,17 @@ HIDDEN size_t make_collection_url(struct buf *buf, const char *urlprefix, int ha
const char *owner = mbname_userid(mbname);
if (!owner) owner = "";

if (config_getswitch(IMAPOPT_FASTMAILSHARING)) {
buf_printf(buf, "%s/%s/", haszzzz ? "zzzz" : USER_COLLECTION_PREFIX, owner);
}
else {
buf_printf(buf, "%s/", USER_COLLECTION_PREFIX);
buf_printf(buf, "%s/", USER_COLLECTION_PREFIX);

if (*userid) {
buf_printf(buf, "%s/", userid);
if (*userid) {
buf_printf(buf, "%s/", userid);

if (strcmp(owner, userid)) {
/* Encode shared collection as: <owner> "." <mboxname> */
buf_printf(buf, "%s%c", owner, SHARED_COLLECTION_DELIM);
}
if (strcmp(owner, userid)) {
/* Encode shared collection as: <owner> "." <mboxname> */
buf_printf(buf, "%s%c", owner, SHARED_COLLECTION_DELIM);
}
else buf_printf(buf, "%s/", owner);
}
else buf_printf(buf, "%s/", owner);
}

size_t len = buf_len(buf);
Expand Down Expand Up @@ -5974,11 +5930,6 @@ int propfind_by_collection(const mbentry_t *mbentry, void *rock)
break;
}

/* skip toplevels */
if (config_getswitch(IMAPOPT_FASTMAILSHARING) && *p == '#')
goto done;


/* Open mailbox for reading */
if ((r = mailbox_open_irl(mboxname, &mailbox))) {
syslog(LOG_INFO, "mailbox_open_irl(%s) failed: %s",
Expand All @@ -5990,22 +5941,12 @@ int propfind_by_collection(const mbentry_t *mbentry, void *rock)
fctx->record = NULL;

if (!fctx->req_tgt->resource) {
/* we always have zzzz if it's already in the URL */
int haszzzz = fctx->req_tgt->flags & TGT_USER_ZZZZ;

mbname_t *mbname = mbname_from_intname(mboxname);
if (!mbname_domain(mbname))
mbname_set_domain(mbname, httpd_extradomain);

/* we also need to deal with the discovery case,
* where mboxname doesn't match request path */
if (fctx->req_tgt->userid &&
strcmpsafe(mbname_userid(mbname), fctx->req_tgt->userid)) {
haszzzz = 1;
}

size_t len = make_collection_url(&writebuf, fctx->req_tgt->namespace->prefix,
haszzzz, mbname, fctx->req_tgt->userid);
mbname, fctx->req_tgt->userid);

mbname_free(&mbname);

Expand Down Expand Up @@ -6315,12 +6256,6 @@ EXPORTED int meth_propfind(struct transaction_t *txn, void *params)
if (txn->req_tgt.mbentry)
propfind_by_collection(txn->req_tgt.mbentry, &fctx);
}
else if (config_getswitch(IMAPOPT_FASTMAILSHARING)) {
/* Add responses for all visible collections */
mboxlist_usermboxtree(httpd_userid, httpd_authstate,
propfind_by_collection,
&fctx, MBOXTREE_PLUS_RACL);
}
else if (txn->req_tgt.mbentry || (httpd_userisanonymous && config_getswitch(IMAPOPT_ALLOWANONYMOUSLOGIN))) {
/* Add responses for all contained collections */
fctx.prefer &= ~PREFER_NOROOT;
Expand Down
2 changes: 1 addition & 1 deletion imap/http_dav.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ __attribute__((nonnull(1))) struct mime_type_t *get_accept_type(const char **hdr
int parse_xml_body(struct transaction_t *txn, xmlNodePtr *root,
const char *mimetype);

size_t make_collection_url(struct buf *buf, const char *urlprefix, int haszzzz,
size_t make_collection_url(struct buf *buf, const char *urlprefix,
const mbname_t *mbname, const char *userid);

/* Initialize an XML tree */
Expand Down
4 changes: 2 additions & 2 deletions imap/http_dav_sharing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ HIDDEN int notify_post(struct transaction_t *txn)
mbname = mbname_from_intname(mboxname);
if (!mbname_domain(mbname)) mbname_set_domain(mbname, httpd_extradomain);

make_collection_url(&txn->buf, url_prefix, /*haszzzz*/0, mbname, "");
make_collection_url(&txn->buf, url_prefix, mbname, "");

xml_add_href(type, NULL, buf_cstring(&txn->buf));

Expand All @@ -1153,7 +1153,7 @@ HIDDEN int notify_post(struct transaction_t *txn)

if (add) {
/* Accepted - create URL of sharee's new collection */
make_collection_url(&txn->buf, url_prefix, /*haszzzz*/0,
make_collection_url(&txn->buf, url_prefix,
mbname, txn->req_tgt.userid);

if (legacy) {
Expand Down
3 changes: 1 addition & 2 deletions imap/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ enum {
TGT_SCHED_OUTBOX,
TGT_MANAGED_ATTACH,
TGT_DRIVE_ROOT,
TGT_DRIVE_USER,
TGT_USER_ZZZZ
TGT_DRIVE_USER
};

/* Function to parse URI path and generate a mailbox name */
Expand Down
2 changes: 1 addition & 1 deletion imap/jmap_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3102,7 +3102,7 @@ HIDDEN int jmap_set_sharewith(struct mailbox *mbox,
if (!mbname_domain(mbname)) mbname_set_domain(mbname, httpd_extradomain);

make_collection_url(&irock.resource, irock.tgt.namespace->prefix,
/*haszzzz*/0, mbname, mbname_userid(mbname));
mbname, mbname_userid(mbname));

/* Create a request target for this collection */
irock.tgt.flags = TGT_DAV_SHARED; // prevent old-style sharing redirect
Expand Down
3 changes: 0 additions & 3 deletions lib/imapoptions
Original file line number Diff line number Diff line change
Expand Up @@ -3278,9 +3278,6 @@ of the incoming network interface, or if no record is found, the
{ "caringo_port", 80, INT, "3.0.0" }
/* The port of the caringo server (caringo_hostname); default is 80. */

{ "fastmailsharing", 0, SWITCH, "3.0.0" }
/* If enabled, use FastMail style sharing (oldschool full server paths) */

/*
.SH SEE ALSO
.PP
Expand Down

0 comments on commit 61b0c1d

Please sign in to comment.