/*
	Copyright (c) 2010 by Dennis Schridde

	This file is part of dovecot-metadata.

	dovecot-metadata is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	dovecot-metadata is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with dovecot-metadata.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "mailbox-ext.h"

#include "hex-binary.h"

const char *
mailbox_get_guid_string(struct mailbox *box) {
#if DOVECOT_PREREQ(2,1)
	struct mailbox_metadata metadata;
	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0)
		return NULL;

	return guid_128_to_string(metadata.guid);
#else
	uint8_t guid[MAIL_GUID_128_SIZE];
	if (mailbox_get_guid(box, guid) < 0)
		return NULL;

	return binary_to_hex(guid, sizeof(guid));
#endif
}
