summaryrefslogtreecommitdiff
path: root/lib/message/mu-message-file.hh
blob: 09a9ed3feea9e7816fb4bcbdf33c294771861937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb.bulk@gmail.com>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/

#ifndef MU_MESSAGE_FILE_HH__
#define MU_MESSAGE_FILE_HH__

#include "mu-flags.hh"
#include <utils/mu-result.hh>

namespace Mu {

/*
 * The file-components, ie.
 *     1631819685.fb7b279bbb0a7b66.evergrey:2,RS
 *     => {
 *       "1631819685.fb7b279bbb0a7b66.evergrey",
 *       ':',
 *       "2,",
 *       "RS"
 *     }
 */
struct FileParts {
	std::string	base;	/**< basename */
	char		separator; /**< separator */
	std::string	flags_suffix; /**< suffix (with flags) */
};

/**
 * Get the file-parts for some message-file
 *
 * @param file path to some message file (does not have to exist)
 *
 * @return FileParts for the message file
 */
FileParts message_file_parts(const std::string& file);


struct DirFile {
	std::string	dir;
	std::string	file;
	bool		is_new;
};

/**
 * Get information about the message file componemts
 *
 * @param path message path
 *
 * @return the components for the message file or an error.
 */
Result<DirFile> base_message_dir_file(const std::string& path);



/**
 * Get the Maildir flags from the full path of a mailfile. The flags are as
 * specified in http://cr.yp.to/proto/maildir.html, plus Flag::New for new
 * messages, ie the ones that live in new/. The flags are logically OR'ed. Note
 * that the file does not have to exist; the flags are based on the path only.
 *
 * @param pathname of a mailfile; it does not have to refer to an
 * actual message
 *
 * @return the message flags or an error
 */
Result<Flags> flags_from_path(const std::string& pathname);

/**
 * get the maildir for a certain message path, ie, the path *before*
 * cur/ or new/ and *after* the root.
 *
 * @param path path for some message
 * @param root filesystem root for the maildir
 *
 * @return the maildir or an Error
 */
Result<std::string> maildir_from_path(const std::string& path,
				      const std::string& root);
} // Mu


#endif /* MU_MESSAGE_FILE_HH__ */