dovecot-metadata-plugin-bdf2445e101f/.hg_archival.txt0000644000000000000000000000016611575123055022637 0ustar00usergroup00000000000000repo: ae7e8348c8755ea0c8209c5b5efcc81228530b5e node: bdf2445e101fefc55ffa7bb2c4c5807af0799bd2 branch: default tag: v8 dovecot-metadata-plugin-bdf2445e101f/.hgignore0000644000000000000000000000046111575123055021352 0ustar00usergroup00000000000000Makefile$ Makefile\.in$ ^stamp-h1$ ^metadata-config\.h$ ^metadata-config\.h\.in$ ^ChangeLog$ ^\.cscope ^aclocal\.m4$ ^autom4te\.cache ^configure$ ^configure.lineno$ ^config\. ^depcomp$ ^libtool$ ^install-sh ^ltmain\.sh$ ^m4 ^missing$ ^patches ^src/\.deps ^src/\.libs ~$ \.tar\.gz$ \.pyc$ \.lo$ \.la$ \.o$ dovecot-metadata-plugin-bdf2445e101f/.hgsigs0000644000000000000000000000021411575123055021030 0ustar00usergroup00000000000000fc360cf4ef81fe0b54ea56074d6b6ee9dcb1c3d5 0 iEYEABECAAYFAk30p6cACgkQjqfyF1DtJW689QCfU6UysrMwwqCycZ9EFbyN9Iof5D0AoL/np56Phl9xCZN9hzeaq0qIcszU dovecot-metadata-plugin-bdf2445e101f/.hgtags0000644000000000000000000000015411575123055021024 0ustar00usergroup00000000000000604f64c0f4852e3c0b5fd20b46cb7372791ec91b works-with-dovecot-1.1 fc360cf4ef81fe0b54ea56074d6b6ee9dcb1c3d5 v7 dovecot-metadata-plugin-bdf2445e101f/AUTHORS0000644000000000000000000000011011575123055020606 0ustar00usergroup00000000000000Bernhard Herzog Dennis Schridde dovecot-metadata-plugin-bdf2445e101f/COPYING0000644000000000000000000006363711575123055020620 0ustar00usergroup00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library 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 2.1 of the License, or (at your option) any later version. This library 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 this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! dovecot-metadata-plugin-bdf2445e101f/INSTALL0000644000000000000000000003633211575123055020606 0ustar00usergroup00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. dovecot-metadata-plugin-bdf2445e101f/Makefile.am0000644000000000000000000000023211575123055021577 0ustar00usergroup00000000000000ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src EXTRA_DIST = \ ChangeLog if MAINTAINER_MODE ChangeLog: .hg/dirstate hg log --style=changelog > ChangeLog endif dovecot-metadata-plugin-bdf2445e101f/NEWS0000644000000000000000000000054011575123055020244 0ustar00usergroup000000000000002011-06-12: Version 8 * Fix compliance with RFC 5464 Section 4.2.2 * Minor cleanups 2011-06-10: Version 7 - "Works with Akonadi" * RFC 5464 compatible * imap-annotatemore is a partial implementation of draft-daboo-imap-annotatemore-08 Based on work by Bernhard Herzog (Intevation GmbH) * imap-metadata is a complete implementation of RFC 5464 dovecot-metadata-plugin-bdf2445e101f/README0000644000000000000000000000571311575123055020434 0ustar00usergroup00000000000000Dovecot Plugins implementing Metadata/Annotations ================================================= This is a set of plugins for the Dovecot IMAP server version 1.2 that implement the IMAP METADATA Extension. The goal of the development is to extend dovecot so that it can be used as the IMAP component instead of Cyrus IMAPd in the Kolab server. Overview -------- The IMAP METADATA Extension is still a draft. At the time the implementation was started, the current version of the draft was draft-daboo-imap-annotatemore-14 dated July 13, 2008. The Kolab server uses the older and somewhat different draft-daboo-imap-annotatemore-05. To be able to accommodate both drafts the METADATA implementation will consist of three plugins: metadata-plugin The actual metadata functionality. This follows the draft-daboo-imap-annotatemore-14 specification. imap-annotatemore-plugin Implements the IMAP commands of the older specification draft-daboo-imap-annotatemore-05 as used by Kolab clients and server. Implemented using metadata-plugin. This will only offer what is really needed by Kolab, not all of what was specified in the imap-annotatemore-05. imap-metadata-plugin The IMAP commands of imap-annotatemore-14. This also uses metadata-plugin for the actual storage. Status ------ At this point, the plugins are very incomplete and somewhat experimental. The metadata-plugin works mostly, but private annotation do not work properly and server annotation have not been implemented at all yet. The imap-annotatemore-plugin implements a minimal subset of the the draft specification as needed by Kolab. The imap-metadata-plugin has not been implemented yet. The details of how the metadata are stored will very likely change in future versions and may require manual upgrades. Requirements ------------ Software needed to build and use the plugins: dovecot 1.2 Dovecot must be compiled with at least one dict backend available. Installation ------------ For general information about the autoconf/automake based Installation see INSTALL. Use the --with-dovecot option to specify where the dovecot sources are. When building from a mercurial working copy, run ./autogen.sh first. Configuration ------------- The metadata is stored in a dovecot dict. Dovecot supports several back-ends for dicts. The following describes how to use SQLite as a back-end. Initialize the database (replace with the actual installation directory): ./initsqlite.sh /var/lib/dovecot/metadata-dict.sqlite This scripts writes the contents of a dovecot SQL configuration file to stdout. Put them into e.g. /etc/metadata-dict.conf and add the following line to the dict section of your dovecot.conf: metadata = sqlite:/etc/metadata-dict.conf and the following line to the plugins section: metadata_dict = proxy:/var/run/dovecot/dict-server:metadata dovecot-metadata-plugin-bdf2445e101f/TODO0000644000000000000000000000003711575123055020236 0ustar00usergroup00000000000000* Handle mailbox moves/renames dovecot-metadata-plugin-bdf2445e101f/autogen.sh0000755000000000000000000000017211575123055021547 0ustar00usergroup00000000000000#!/bin/sh echo '+ creating m4/ ...' test -d m4 || mkdir m4 echo '+ running autoreconf ...' autoreconf --force --install dovecot-metadata-plugin-bdf2445e101f/configure.ac0000644000000000000000000000047511575123055022042 0ustar00usergroup00000000000000AC_PREREQ(2.65) AC_INIT([dovecot-metadata],[8],[devurandom@gmx.net]) AM_INIT_AUTOMAKE([1.10 silent-rules]) AM_MAINTAINER_MODE AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src]) AC_PROG_CC_STDC LT_INIT DC_DOVECOT([2.0]) AC_CONFIG_HEADERS([metadata-config.h]) AC_CONFIG_FILES([ Makefile src/Makefile ]) AC_OUTPUT dovecot-metadata-plugin-bdf2445e101f/initsqlite.sh0000755000000000000000000000126511575123055022276 0ustar00usergroup00000000000000#! /bin/sh dbfile=$1 if [ -z "$dbfile" ]; then echo "Usage:" echo " initsqlite DBFILENAME" exit 1 fi case $dbfile in /*) ;; *) echo "the DBFILENAME must be absolute" exit 1 ;; esac rm -f $dbfile sqlite3 $dbfile <. */ #include "dict-ext.h" #include "str.h" #include "dict.h" enum dict_scope dict_get_scope(const char *path) { if (strncasecmp(DICT_PATH_SHARED, path, sizeof(DICT_PATH_SHARED)) == 0) return DICT_SCOPE_SHARED; else if (strncasecmp(DICT_PATH_PRIVATE, path, sizeof(DICT_PATH_PRIVATE)) == 0) return DICT_SCOPE_PRIVATE; return DICT_SCOPE_INVALID; } const char * dict_path_from_scope(enum dict_scope scope) { switch (scope) { case DICT_SCOPE_SHARED: return DICT_PATH_SHARED; case DICT_SCOPE_PRIVATE: return DICT_PATH_PRIVATE; case DICT_SCOPE_INVALID: return ""; } return ""; } struct dict_iterate_multiscope_context { struct dict_iterate_context *dict_ctx; struct dict *dict; enum dict_iterate_flags flags; string_t *path; bool do_shared; bool failed; }; struct dict_iterate_multiscope_context * dict_iterate_multiscope_init(struct dict *dict, const char *path, enum dict_iterate_multiscope_flags flags) { struct dict_iterate_multiscope_context *ctx = i_new(struct dict_iterate_multiscope_context, 1); memset(ctx, 0, sizeof(*ctx)); ctx->dict = dict; ctx->flags = flags & ~DICT_ITERATE_MULTISCOPE_FLAG_MULTISCOPE; ctx->path = str_new(default_pool, 128); if (flags & DICT_ITERATE_MULTISCOPE_FLAG_MULTISCOPE) str_append(ctx->path, DICT_PATH_PRIVATE); str_append(ctx->path, path); ctx->do_shared = (flags & DICT_ITERATE_MULTISCOPE_FLAG_MULTISCOPE); ctx->failed = false; ctx->dict_ctx = dict_iterate_init(ctx->dict, str_c(ctx->path), ctx->flags); return ctx; } bool dict_iterate_multiscope(struct dict_iterate_multiscope_context *ctx, const char **name, const char **value) { i_assert(ctx != NULL); if (ctx == NULL) return false; if (ctx->failed) return false; *name = NULL; while (*name == NULL) { bool ret = dict_iterate(ctx->dict_ctx, name, value); /* we have no more shared/ keys and priv/ was also already iterated over */ if (!ret && !ctx->do_shared) { return false; } /* no more priv/ keys, continue with shared/ */ else if (!ret && ctx->do_shared) { if (dict_iterate_deinit(&ctx->dict_ctx) < 0) { ctx->failed = true; return false; } /* replace priv/ with shared/ */ str_delete(ctx->path, 0, sizeof(DICT_PATH_SHARED)); str_insert(ctx->path, 0, DICT_PATH_PRIVATE); ctx->do_shared = false; ctx->dict_ctx = dict_iterate_init(ctx->dict, str_c(ctx->path), ctx->flags); if (ctx->dict_ctx == NULL) { ctx->failed = true; } continue; } } return true; } int dict_iterate_multiscope_deinit(struct dict_iterate_multiscope_context **ctx) { i_assert(ctx != NULL); if (ctx == NULL) return -1; i_assert(*ctx != NULL); if (*ctx == NULL) return -1; int ret = (*ctx)->failed ? -1 : 0; if (dict_iterate_deinit(&(*ctx)->dict_ctx) < 0) ret = -1; str_free(&(*ctx)->path); i_free(*ctx); return ret; } dovecot-metadata-plugin-bdf2445e101f/src/dict-ext.h0000644000000000000000000000312511575123055022230 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_DICT_EXT_H #define DOVECOT_DICT_EXT_H #include "metadata-global.h" #include #include "dict.h" enum dict_scope { DICT_SCOPE_SHARED, DICT_SCOPE_PRIVATE, DICT_SCOPE_INVALID }; enum dict_scope dict_get_scope(const char *key) ATTR_NONNULL(1); const char * dict_path_from_scope(enum dict_scope scope); struct dict_iterate_multiscope_context; enum dict_iterate_multiscope_flags { DICT_ITERATE_MULTISCOPE_FLAG_MULTISCOPE = 0x1000 }; struct dict_iterate_multiscope_context * dict_iterate_multiscope_init(struct dict *dict, const char *path, enum dict_iterate_multiscope_flags flags) ATTR_NONNULL(1,2); bool dict_iterate_multiscope(struct dict_iterate_multiscope_context *ctx, const char **name, const char **value) ATTR_NONNULL(1,2,3); int dict_iterate_multiscope_deinit(struct dict_iterate_multiscope_context **ctx) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/src/imap-annotatemore-plugin.c0000644000000000000000000004251211575123055025421 0ustar00usergroup00000000000000/* Copyright (c) 2008 by Intevation GmbH / Bernhard Herzog 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 . */ #include "metadata-global.h" #include "str.h" #include "imap-common.h" #include "imap-client.h" #include "imap-quote.h" #include "mailbox-list.h" #include #include "str-ext.h" #include "metadata-entry-private.h" #include "metadata-backend.h" /* The IMAP Annotatemore plugin is a partial implementation of draft-daboo-imap-annotatemore-08 */ const char *imap_annotatemore_plugin_version = DOVECOT_VERSION; const char *imap_annotatemore_plugin_dependencies[] = { "metadata", NULL }; static struct module *imap_annotatemore_module; static void (*next_hook_client_created)(struct client **client); enum attribute_properties { ATTR_INVALID = 0x0001, ATTR_PRIVATE = 0x0002, ATTR_PUBLIC = 0x0004, ATTR_BOTH = ATTR_PUBLIC | ATTR_PRIVATE, }; static bool validate_entry_name(struct client_command_context *cmd, const char *entry) { if (entry == NULL) { client_send_command_error(cmd, "Missing entry name."); return FALSE; } if (entry[0] != '/' && entry[0] != '*' && entry[0] != '%') { client_send_command_error(cmd, "Entry name must start with slash or be a glob."); return FALSE; } return TRUE; } static enum attribute_properties validate_attribute_name(struct client_command_context *cmd, const char *attribute) { if (attribute == NULL) { client_send_command_error(cmd, "Missing or NIL attribute name."); return ATTR_INVALID; } if (strcmp(attribute, "value.shared") == 0) { return ATTR_PUBLIC; } else if (strcmp(attribute, "value.priv") == 0) { return ATTR_PRIVATE; } else if (strcmp(attribute, "value") == 0) { return ATTR_BOTH; } else if (strchr(attribute, '*')) { return ATTR_BOTH; } else if (strchr(attribute, '%')) { client_send_command_error(cmd, "'%' globs not supported."); return ATTR_INVALID; } else { client_send_command_error(cmd, "Only 'value.shared' and 'value.priv' attributes" " are supported '.'"); return ATTR_INVALID; } } static const char * entry_scopes[ENTRY_SCOPE_MAX] = { "private/", /* ENTRY_SCOPE_PRIVATE */ "shared/" /* ENTRY_SCOPE_SHARED */ }; static const char * entry_types[ENTRY_TYPE_MAX] = { "vendor/", /* ENTRY_TYPE_VENDOR */ "", /* ENTRY_TYPE_RFC */ }; static const char ** entry_subtypes_rfc[ENTRY_SUBJECT_MAX] = { (const char*[]){ // server "comment", "admin", NULL }, (const char*[]){ // mailbox "comment", NULL } }; /* validates that the part after /vendor conforms to the RFC */ static ATTR_NONNULL(1) bool is_valid_annotatemore_vendor_name(const char *name) { const char *lastslash = NULL, *lastcr = NULL; int num_components = 2; for (const char *c = name; *c != '\0'; c++) { switch (*c) { case '/': // Two consecutive slashes, or a slash at the end are an error if (lastslash == c-1 || *(c+1) == '\0') { return false; } lastslash = c; num_components++; break; case '*': case '%': return false; case '\r': lastcr = c; break; case '\n': // line ending has to be CRLF if (lastcr != c-1) { return false; } break; default: break; } } return num_components >= 4; } static ATTR_NONNULL(1) bool is_valid_annotatemore_subtype_name(const char *name, enum metadata_entry_subject subject) { bool found_subtype = false; i_assert(subject > 0 && subject < ENTRY_SUBJECT_MAX); for (const char **subtype = entry_subtypes_rfc[subject]; *subtype != NULL; subtype++) { size_t subtype_len = strlen(*subtype); if (strncasecmp(name, *subtype, subtype_len) == 0) { found_subtype = true; } } return found_subtype; } /* sets entry->type and returns remaining string */ static ATTR_NONNULL(1) enum metadata_entry_type parse_entry_type(const char **name, enum metadata_entry_subject subject) { if (**name == '\0') return ENTRY_TYPE_NONE; for (int type = 0; type < ENTRY_TYPE_MAX; type++) { size_t type_len = strlen(entry_types[type]); if (strncasecmp(*name, entry_types[type], type_len) == 0) { *name += type_len; switch (type) { case ENTRY_TYPE_RFC: if (!is_valid_annotatemore_subtype_name(*name, subject)) return ENTRY_TYPE_MAX; break; case ENTRY_TYPE_VENDOR: if (!is_valid_annotatemore_vendor_name(*name)) return ENTRY_TYPE_MAX; break; } return type; } } return ENTRY_TYPE_MAX; } static ATTR_NONNULL(2) const char * backend_name(enum metadata_entry_scope scope, const char *name) { if (name == NULL) return NULL; string_t *backend_name = t_str_new(128); str_append(backend_name, "/"); str_append(backend_name, entry_scopes[scope]); str_append(backend_name, name); return str_c(backend_name); } /* fill entry with data parsed from entry->full_name */ static ATTR_NONNULL(3) struct metadata_entry * parse_entry(struct mailbox *box, enum metadata_entry_scope scope, const char *name, const char *value) { if (name == NULL || *name == '\0' || *name++ != '/') return NULL; string_t *backend_name = t_str_new(128); str_append(backend_name, "/"); str_append(backend_name, entry_scopes[scope]); str_append(backend_name, name); enum metadata_entry_type type = parse_entry_type(&name, box ? ENTRY_SUBJECT_MAILBOX : ENTRY_SUBJECT_SERVER); if (type >= ENTRY_TYPE_MAX) return NULL; return metadata_entry_alloc(box, str_c(backend_name), value); } static void send_annotation_line(struct client_command_context *cmd, struct mailbox *box, const char *entry_name, const char *value, bool private) { if (value != NULL) { const char *mailbox_name = mailbox_get_vname(box); const char *str = t_strdup_printf( "* ANNOTATION %s %s (value.%s %s)", mailbox_name, entry_name, private ? "priv" : "shared", value ); client_send_line(cmd->client, str); } } static void get_and_send_annotation(struct client_command_context *cmd, struct mailbox *box, const char *entry_name, enum attribute_properties scope) { if (strchr(entry_name, '*')) { int entrylastchar = strlen(entry_name); if (entrylastchar > 0) entrylastchar--; /* We do not support more than one glob, and at no other location than the end */ if (strchr_num(entry_name, '*') == 1 && entry_name[entrylastchar] == '*') { const char *entrypattern = t_strdup_until(entry_name, &entry_name[entrylastchar]); if ((scope & ATTR_PUBLIC) != 0) { struct metadata_entry *entry = metadata_entry_alloc(box, backend_name(ENTRY_SCOPE_SHARED, entrypattern), NULL); struct metadata_iterate_context *iter = metadata_iterate_init(box, entry, METADATA_ITERATE_DEPTH_INF); while (metadata_iterate(iter, entry)) { const char *name = metadata_entry_get_name(entry) + strlen(entry_scopes[ENTRY_SCOPE_SHARED]); const char *value = metadata_entry_get_value(entry); send_annotation_line(cmd, box, name, value, FALSE); } if (metadata_iterate_deinit(&iter) < 0) { client_send_tagline(cmd, "NO Iterating metadata failed."); return; } } if ((scope & ATTR_PRIVATE) != 0) { struct metadata_entry *entry = metadata_entry_alloc(box, backend_name(ENTRY_SCOPE_PRIVATE, entrypattern), NULL); struct metadata_iterate_context *iter = metadata_iterate_init(box, entry, METADATA_ITERATE_DEPTH_INF); while (metadata_iterate(iter, entry)) { const char *name = metadata_entry_get_name(entry) + strlen(entry_scopes[ENTRY_SCOPE_SHARED]); const char *value = metadata_entry_get_value(entry); send_annotation_line(cmd, box, name, value, TRUE); } if (metadata_iterate_deinit(&iter) < 0) { client_send_tagline(cmd, "NO Iterating metadata failed."); return; } } } else { client_send_command_error(cmd, "'*' globs only supported at end of pattern."); return; } } else if (strchr(entry_name, '%')) { client_send_command_error(cmd, "'%' globs not supported."); return; } else { if ((scope & ATTR_PUBLIC) != 0) { struct metadata_entry *entry = metadata_entry_alloc(box, backend_name(ENTRY_SCOPE_SHARED, entry_name), NULL); if (entry == NULL) { client_send_tagline(cmd, "NO Allocating entry failed."); return; } int success = metadata_get_entry(entry, cmd->client->user); if (success < 0) { client_send_tagline(cmd, "NO Getting entry failed."); return; } else if (success > 0) { send_annotation_line(cmd, box, entry->name, entry->value, FALSE); } } if ((scope & ATTR_PRIVATE) != 0) { struct metadata_entry *entry = metadata_entry_alloc(box, backend_name(ENTRY_SCOPE_PRIVATE, entry_name), NULL); if (entry == NULL) { client_send_tagline(cmd, "NO Allocating entry failed."); return; } int success = metadata_get_entry(entry, cmd->client->user); if (success < 0) { client_send_tagline(cmd, "NO Getting entry failed."); return; } else if (success > 0) { send_annotation_line(cmd, box, entry->name, entry->value, TRUE); } } } } static bool extract_single_value(struct client_command_context *cmd, const struct imap_arg *attribute, const char **value_r) { const struct imap_arg *attrlist = NULL; unsigned int attrcount = 0; if (!imap_arg_get_list_full(attribute, &attrlist, &attrcount)) { // Actually this should never happen, since we first test args[1].type == IMAP_ARG_LIST ! */ i_error("metadata: got attributes of non-list type after confirming they were of correct type!"); client_send_command_error(cmd, "Attributes must be of list type."); return FALSE; } if (attrcount == 1) { if (!imap_arg_get_astring(&attrlist[0], value_r)) { client_send_command_error(cmd, "Value must be of string type."); return FALSE; } return TRUE; } else { client_send_tagline(cmd, "NO Lists of entries not yet implemented."); return FALSE; } } static bool cmd_getannotation(struct client_command_context *cmd) { const struct imap_arg *args; const char *mailbox_name; const char *entry_name; const char *attribute; enum attribute_properties attribute_properties; if (!client_read_args(cmd, 3, 0, &args)) return FALSE; if (!imap_arg_get_astring(&args[0], &mailbox_name)) { client_send_command_error(cmd, "Mailbox name must be of string type."); return TRUE; } if (mailbox_name == NULL) { client_send_command_error(cmd, "Missing mailbox name."); return TRUE; } if (*mailbox_name == '\0') { client_send_tagline(cmd, "NO Server annotations not yet" " implemented."); return TRUE; } if (args[1].type == IMAP_ARG_LIST) { if (!extract_single_value(cmd, &args[1], &entry_name)) return TRUE; } else { if (!imap_arg_get_astring(&args[1], &entry_name)) { client_send_command_error(cmd, "Entry name must be of string type."); return TRUE; } } if (!validate_entry_name(cmd, entry_name)) return TRUE; if (args[2].type == IMAP_ARG_LIST) { if (!extract_single_value(cmd, &args[2], &attribute)) return TRUE; } else { if (!imap_arg_get_astring(&args[2], &attribute)) { client_send_command_error(cmd, "Attribute must be of string type."); return TRUE; } } attribute_properties = validate_attribute_name(cmd, attribute); if (attribute_properties & ATTR_INVALID) return TRUE; if (str_has_wildcards(mailbox_name)) { for (const struct mail_namespace *ns = cmd->client->user->namespaces; ns != NULL; ns = ns->next) { const struct mailbox_info *info = NULL; struct mailbox_list_iterate_context *ctx = mailbox_list_iter_init(ns->list, mailbox_name, 0); while ((info = mailbox_list_iter_next(ctx)) != NULL) { i_debug("Getting info for mailbox '%s'", info->name); struct mailbox *box = mailbox_alloc(ns->list, info->name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return TRUE; } get_and_send_annotation(cmd, box, entry_name, attribute_properties); mailbox_free(&box); } if (mailbox_list_iter_deinit(&ctx) < 0) { client_send_tagline(cmd, "NO Iterating mailboxes failed."); } } } else { struct mail_namespace *ns = mail_namespace_find(cmd->client->user->namespaces, &mailbox_name); if (ns == NULL) { client_send_tagline(cmd, "NO Mailbox not found."); return TRUE; } struct mailbox *box = mailbox_alloc(ns->list, mailbox_name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return TRUE; } get_and_send_annotation(cmd, box, entry_name, attribute_properties); mailbox_free(&box); } client_send_tagline(cmd, "OK Completed."); return TRUE; } static bool pair_extract_value(struct client_command_context *cmd, const struct imap_arg *attributes, const char **value_r, bool *private_r) { const struct imap_arg *pairs; unsigned int count; if (!imap_arg_get_list_full(attributes, &pairs, &count)) { client_send_command_error(cmd, "Attributes parameter must be a list" " of attribute value pairs."); return FALSE; } if (count % 2 != 0) { client_send_command_error(cmd, "List of attribute value pairs" " must have an even number of elements"); return FALSE; } if (count == 0) { client_send_command_error(cmd, "List of attribute value pairs" " is empty"); return FALSE; } if (count == 2) { enum attribute_properties properties; const char *tmp; if (!imap_arg_get_astring(&pairs[0], &tmp)) { client_send_command_error(cmd, "Attribute must be of string type."); return FALSE; } properties = validate_attribute_name(cmd, tmp); if ((properties & ATTR_INVALID) != 0) return FALSE; if ((properties & ATTR_BOTH) == ATTR_BOTH) { client_send_command_error(cmd, "Attribute must end in .priv" " or .shared for SETANNOTATION"); return FALSE; } if (!imap_arg_get_astring(&pairs[1], value_r)) { client_send_command_error(cmd, "Value must be of string type."); return FALSE; } *private_r = ((properties & ATTR_PRIVATE) != 0); return TRUE; } client_send_tagline(cmd, "NO only setting single attributes supported"); return FALSE; } static bool cmd_setannotation(struct client_command_context *cmd) { const struct imap_arg *args; const char *mailbox_name; const char *entry_name; const char *value; bool private; if (!client_read_args(cmd, 3, 0, &args)) return FALSE; if (!imap_arg_get_astring(&args[0], &mailbox_name)) { client_send_command_error(cmd, "Mailbox name must be of string type."); return TRUE; } if (mailbox_name == NULL) { client_send_command_error(cmd, "Missing mailbox name."); return TRUE; } if (*mailbox_name == '\0') { client_send_tagline(cmd, "NO Server annotations not yet" " implemented."); return TRUE; } if (args[1].type == IMAP_ARG_LIST) { client_send_tagline(cmd, "NO Lists of entries not yet implemented."); return TRUE; } if (!imap_arg_get_astring(&args[1], &entry_name)) { client_send_command_error(cmd, "Entry name must be of string type."); return TRUE; } if (entry_name == NULL) { client_send_tagline(cmd, "NO Entry name is NULL."); return true; } if (!validate_entry_name(cmd, entry_name)) return TRUE; if (!pair_extract_value(cmd, &args[2], &value, &private)) return TRUE; struct mail_namespace *ns = mail_namespace_find(cmd->client->user->namespaces, &mailbox_name); if (ns == NULL) { client_send_tagline(cmd, "NO Mailbox not found."); return TRUE; } struct mailbox *box = mailbox_alloc(ns->list, mailbox_name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return TRUE; } struct metadata_entry *entry = parse_entry(box, private ? ENTRY_SCOPE_PRIVATE : ENTRY_SCOPE_SHARED, entry_name, value); if (entry == NULL) { client_send_tagline(cmd, "NO Parsing entry failed."); mailbox_free(&box); return TRUE; } if (metadata_set_entry(entry, cmd->client->user) < 0) { client_send_tagline(cmd, "NO Setting entry failed."); mailbox_free(&box); return TRUE; } client_send_tagline(cmd, "OK Completed."); mailbox_free(&box); return TRUE; } static void imap_annotatemore_client_created(struct client **client) { if (mail_user_is_plugin_loaded((*client)->user, imap_annotatemore_module)) str_append((*client)->capability_string, " ANNOTATEMORE"); if (next_hook_client_created != NULL) next_hook_client_created(client); } void imap_annotatemore_plugin_init(struct module *module) { command_register("GETANNOTATION", cmd_getannotation, 0); command_register("SETANNOTATION", cmd_setannotation, 0); imap_annotatemore_module = module; next_hook_client_created = hook_client_created; hook_client_created = imap_annotatemore_client_created; } void imap_annotatemore_plugin_deinit(void) { command_unregister("SETANNOTATION"); command_unregister("GETANNOTATION"); hook_client_created = next_hook_client_created; } dovecot-metadata-plugin-bdf2445e101f/src/imap-arg-ext.c0000644000000000000000000000363011575123055022776 0ustar00usergroup00000000000000/* 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 . */ #include "imap-arg-ext.h" #include bool imap_arg_get_astringlist(const struct imap_arg *arg, const char ***list_r) { i_assert(list_r != NULL); if (list_r == NULL) { return false; } if (*list_r != NULL) { free(*list_r); *list_r = NULL; } size_t list_size = 0; if (arg->type == IMAP_ARG_LIST) { // entries const struct imap_arg *arglist = NULL; if (!imap_arg_get_list(arg, &arglist)) { return false; } while (arglist[list_size].type != IMAP_ARG_EOL) { const char *astring = NULL; if (!imap_arg_get_astring(&arglist[list_size], &astring)) { free(*list_r); *list_r = NULL; return false; } *list_r = realloc(*list_r, (list_size+2)*sizeof(*list_r)); if (*list_r == NULL) { return false; } (*list_r)[list_size] = astring; list_size++; } } else if (IMAP_ARG_TYPE_IS_ASTRING(arg->type)) { const char *astring = NULL; if (!imap_arg_get_astring(arg, &astring)) { return false; } *list_r = realloc(*list_r, (list_size+2)*sizeof(*list_r)); if (*list_r == NULL) { return false; } (*list_r)[list_size] = astring; list_size++; } else { return false; } (*list_r)[list_size] = NULL; return true; } dovecot-metadata-plugin-bdf2445e101f/src/imap-arg-ext.h0000644000000000000000000000174211575123055023005 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_IMAP_ARG_EXT_H #define DOVECOT_IMAP_ARG_EXT_H #include "metadata-global.h" #include #include "imap-arg.h" bool imap_arg_get_astringlist(const struct imap_arg *arg, const char ***list_r) ATTR_WARN_UNUSED_RESULT; #endif dovecot-metadata-plugin-bdf2445e101f/src/imap-metadata-plugin.c0000644000000000000000000004204311575123055024504 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-global.h" #include "imap-common.h" #include "imap-client.h" #include "imap-quote.h" #include #include #include "str-ext.h" #include "imap-arg-ext.h" #include "dict-ext.h" #include "metadata-entry.h" #include "metadata-backend.h" #include "metadata-mail-user-module-private.h" /* The IMAP Metadata plugin is an implementation of RFC 5464 */ const char *imap_metadata_plugin_version = DOVECOT_VERSION; const char *imap_metadata_plugin_dependencies[] = { "metadata", NULL }; static struct module *imap_metadata_module; static void (*next_hook_client_created)(struct client **client); static const char * entry_scopes[ENTRY_SCOPE_MAX] = { "private/", /* ENTRY_SCOPE_PRIVATE */ "shared/" /* ENTRY_SCOPE_SHARED */ }; static const char * entry_types[ENTRY_TYPE_MAX] = { "vendor/", /* ENTRY_TYPE_VENDOR */ "", /* ENTRY_TYPE_RFC */ }; static const char ** entry_subtypes_rfc[ENTRY_SUBJECT_MAX] = { (const char*[]){ // server "comment", "admin", NULL }, (const char*[]){ // mailbox "comment", NULL } }; enum getmetadata_option { GETMETADATA_OPTION_MAXSIZE, GETMEDADATA_OPTION_DEPTH }; struct option_definition { const char *name; int num_values; enum getmetadata_option option; }; static struct option_definition getmetadata_options[] = { {"maxsize", 1, GETMETADATA_OPTION_MAXSIZE}, {"depth", 1, GETMEDADATA_OPTION_DEPTH}, {NULL, 0, 0} }; static struct option_definition * parse_getmetadata_option(const char *option) { struct option_definition *optdef = getmetadata_options; while (optdef->name != NULL) { if (strcasecmp(optdef->name, option) == 0) { return optdef; } optdef++; } return NULL; } static int parse_getmetadata_depth(const char *value) { if (!str_is_numeric(value, '\0')) { if (strcasecmp(value, "infinity")) return METADATA_ITERATE_DEPTH_INF; return -1; } char *end = NULL; long int val = strtol(value, &end, 10); if (end == value) return -2; if (val == LONG_MAX) return -3; if (val < 0) return -4; return val; } static int parse_getmetadata_maxsize(const char *value) { if (!str_is_numeric(value, '\0')) return -1; char *end = NULL; long int val = strtol(value, &end, 10); if (end == value) return -2; if (val == LONG_MAX) return -3; if (val < 0) return -4; return val; } /* validates that the part after /vendor conforms to the RFC */ static ATTR_NONNULL(1) bool is_valid_rfc5464_vendor_name(const char *name) { const char *lastslash = NULL, *lastcr = NULL; int num_components = 3; // "vendor/" already includes the slash of component No3 for (const char *c = name; *c != '\0'; c++) { switch (*c) { case '/': // Two consecutive slashes, or a slash at the end are an error if (lastslash == c-1 || *(c+1) == '\0') { return false; } lastslash = c; num_components++; break; case '*': case '%': return false; case '\r': lastcr = c; break; case '\n': // line ending has to be CRLF if (lastcr != c-1) { return false; } break; default: break; } } return num_components >= 4; } static ATTR_NONNULL(1) bool is_valid_rfc5464_subtype_name(const char *name, enum metadata_entry_subject subject) { bool found_subtype = false; i_assert(subject > 0 && subject < ENTRY_SUBJECT_MAX); for (const char **subtype = entry_subtypes_rfc[subject]; *subtype != NULL; subtype++) { size_t subtype_len = strlen(*subtype); if (strncasecmp(name, *subtype, subtype_len) == 0 && name[subtype_len] == '\0') { found_subtype = true; } } return found_subtype; } /* sets entry->scope and returns remaining string */ static ATTR_NONNULL(1) enum metadata_entry_scope parse_entry_scope(const char **name) { for (int scope = 0; scope < ENTRY_SCOPE_MAX; scope++) { size_t scope_len = strlen(entry_scopes[scope]); if (strncasecmp(*name, entry_scopes[scope], scope_len) == 0) { *name += scope_len; return scope; } } return ENTRY_SCOPE_MAX; } /* sets entry->type and returns remaining string */ static ATTR_NONNULL(1) enum metadata_entry_type parse_entry_type(const char **name, enum metadata_entry_subject subject) { for (int type = 0; type < ENTRY_TYPE_MAX; type++) { size_t type_len = strlen(entry_types[type]); if (strncasecmp(*name, entry_types[type], type_len) == 0) { *name += type_len; switch (type) { case ENTRY_TYPE_RFC: if (!is_valid_rfc5464_subtype_name(*name, subject)) return ENTRY_TYPE_MAX; break; case ENTRY_TYPE_VENDOR: if (!is_valid_rfc5464_vendor_name(*name)) return ENTRY_TYPE_MAX; break; } return type; } } return ENTRY_TYPE_MAX; } /* fill entry with data parsed from entry->full_name */ static ATTR_NONNULL(2) struct metadata_entry * parse_entry(struct mailbox *box, const char *name, const char *value) { const char *name_tmp = name; if (name_tmp == NULL || *name_tmp++ != '/') return NULL; enum metadata_entry_scope scope = parse_entry_scope(&name_tmp); if (scope >= ENTRY_SCOPE_MAX) return NULL; enum metadata_entry_type type = parse_entry_type(&name_tmp, box ? ENTRY_SUBJECT_MAILBOX : ENTRY_SUBJECT_SERVER); if (type >= ENTRY_TYPE_MAX) return NULL; return metadata_entry_alloc(box, name, value); } static int get_and_send_entry(struct client_command_context *cmd, struct mailbox *box, const char *name, int depth, int maxsize, int *longentries) { if (str_has_wildcards(name)) { client_send_tagline(cmd, "NO Wildcards in entry name not allowed."); return -1; } if (depth == 0) { struct metadata_entry *entry = parse_entry(box, name, NULL); if (entry == NULL) { client_send_tagline(cmd, "NO Parsing entry failed."); return -1; } int success = metadata_get_entry(entry, cmd->client->user); if (success < 0) { i_assert(0); client_send_tagline(cmd, "NO Getting entry failed."); return -1; } else if (success > 0) { const char *str = t_strdup_printf( "* METADATA %s (%s %s)", mailbox_get_vname(box), metadata_entry_get_name(entry), metadata_entry_get_value(entry) ); return client_send_line(cmd->client, str); } return 0; } struct metadata_entry *entry = metadata_entry_alloc(box, name, NULL); int num_entries = 0; string_t *str = t_str_new(128); str_append_printf(str, "* METADATA %s (", mailbox_get_vname(box)); struct metadata_iterate_context *iter = metadata_iterate_init(box, entry, depth); while (metadata_iterate(iter, entry)) { const char *name = metadata_entry_get_name(entry); const char *value = metadata_entry_get_value(entry); /* only respect maxsize if it is not 'undefined' */ if (maxsize > 0) { size_t val_len = strlen(value); if (val_len > maxsize && val_len > *longentries) { *longentries = val_len; continue; } } str_append_printf(str, "%s %s ", name, value); num_entries++; } if (metadata_iterate_deinit(&iter) < 0) { client_send_tagline(cmd, "NO Iterating metadata failed."); return -1; } str_append(str, ")"); if (num_entries > 0) { return client_send_line(cmd->client, str_c(str)); } return 0; } static bool cmd_getmetadata(struct client_command_context *cmd) { const struct imap_arg *args; int maxsize = 0, depth = 0; if (!client_read_args(cmd, 0, 0, &args)) return false; if (args[0].type == IMAP_ARG_LIST) { // options const struct imap_arg *arglist = NULL; if (!imap_arg_get_list(&args[0], &arglist)) { client_send_command_error(cmd, "Cannot read options, list expected."); return true; } while (arglist->type != IMAP_ARG_EOL) { if (!IMAP_ARG_TYPE_IS_ASTRING(arglist->type)) { client_send_command_error(cmd, "Option not a string."); return true; } const char *option = NULL; if (!imap_arg_get_astring(arglist, &option)){ client_send_command_error(cmd, "Cannot read option, string expected."); return true; } struct option_definition *optdef = parse_getmetadata_option(option); if (optdef == NULL) { const char *estr = t_strdup_printf("Unknown option: %s.", option); client_send_command_error(cmd, estr); return true; } arglist++; const char *values[optdef->num_values]; memset(values, 0, sizeof(*values) * optdef->num_values); for (int i = 0; i < optdef->num_values; i++) { if (!IMAP_ARG_TYPE_IS_ASTRING(arglist[i].type)) { const char *estr = t_strdup_printf( "Value %d/%d of %s not a string.", i, optdef->num_values, option ); client_send_command_error(cmd, estr); return true; } if (!imap_arg_get_astring(&arglist[i], &values[i])){ const char *estr = t_strdup_printf( "Cannot read value %d/%d of %s, string expected.", i, optdef->num_values, option ); client_send_command_error(cmd, estr); return true; } } switch (optdef->option) { case GETMEDADATA_OPTION_DEPTH: depth = parse_getmetadata_depth(values[0]); if (depth < 0) { client_send_command_error(cmd, "Value 1/1 of DEPTH is not numeric and positive or \"infinity\"."); return true; } break; case GETMETADATA_OPTION_MAXSIZE: maxsize = parse_getmetadata_maxsize(values[0]); if (maxsize < 0) { client_send_command_error(cmd, "Value 1/1 of MAXSIZE is not numeric and positive."); return true; } break; } arglist += optdef->num_values; } args++; } if (!IMAP_ARG_TYPE_IS_ASTRING(args[0].type)) { // mailbox name client_send_command_error(cmd, "Mailbox name not a string."); return true; } const char *mailbox_name = NULL; if (!imap_arg_get_astring(&args[0], &mailbox_name)){ client_send_command_error(cmd, "Cannot read mailbox name, string expected."); return true; } if (mailbox_name == NULL) { client_send_tagline(cmd, "NO Mailbox name is NULL."); return true; } const char **entry_names = NULL; if (!imap_arg_get_astringlist(&args[1], &entry_names)) { client_send_command_error(cmd, "Cannot read entries, string or list of strings expected."); return true; } int warn_longentries = 0; if (str_has_wildcards(mailbox_name)) { for (const struct mail_namespace *ns = cmd->client->user->namespaces; ns != NULL; ns = ns->next) { const struct mailbox_info *info = NULL; struct mailbox_list_iterate_context *ctx = mailbox_list_iter_init(ns->list, mailbox_name, 0); while ((info = mailbox_list_iter_next(ctx)) != NULL) { i_debug("Getting info for mailbox '%s'", info->name); struct mailbox *box = mailbox_alloc(ns->list, info->name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return TRUE; } const char **entry_name = entry_names; while (*entry_name != NULL) { if (get_and_send_entry(cmd, box, *entry_name, depth, maxsize, &warn_longentries) < 0) { /* get_and_send_entry outputs the response for the client, already */ mailbox_free(&box); return true; } entry_name++; } mailbox_free(&box); } if (mailbox_list_iter_deinit(&ctx) < 0) { client_send_tagline(cmd, "NO Iterating mailboxes failed."); } } } else { struct mailbox *box = NULL; /* empty mailbox_name -> box=NULL -> server scope */ if (*mailbox_name != '\0') { struct mail_namespace *ns = mail_namespace_find(cmd->client->user->namespaces, &mailbox_name); if (ns == NULL) { client_send_tagline(cmd, "NO Mailbox not found."); return true; } box = mailbox_alloc(ns->list, mailbox_name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return true; } } const char **entry_name = entry_names; while (*entry_name != NULL) { if (get_and_send_entry(cmd, box, *entry_name, depth, maxsize, &warn_longentries) < 0) { /* get_and_send_entry outputs the response for the client, already */ mailbox_free(&box); return true; } entry_name++; } mailbox_free(&box); } free(entry_names); const char *response; if (warn_longentries > 0) { response = t_strdup_printf("OK [METADATA LONGENTRIES %d] Completed.", warn_longentries); } else { response = "OK Completed."; } client_send_tagline(cmd, response); return true; } static bool cmd_setmetadata(struct client_command_context *cmd) { const struct imap_arg *args; if (!client_read_args(cmd, 0, 0, &args)) return false; if (!IMAP_ARG_TYPE_IS_ASTRING(args[0].type)) { // mailbox name client_send_command_error(cmd, "Mailbox name not a string."); return true; } const char *mailbox_name = NULL; if (!imap_arg_get_astring(&args[0], &mailbox_name)){ client_send_command_error(cmd, "Cannot read mailbox name, string expected."); return true; } if (mailbox_name == NULL) { client_send_tagline(cmd, "NO Mailbox name is NULL."); return true; } struct mailbox *box = NULL; /* empty name -> box=NULL -> server scope */ if (*mailbox_name != '\0') { struct mail_namespace *ns = mail_namespace_find(cmd->client->user->namespaces, &mailbox_name); if (ns == NULL) { client_send_tagline(cmd, "NO Mailbox not found."); return true; } box = mailbox_alloc(ns->list, mailbox_name, MAILBOX_FLAG_READONLY); if (box == NULL) { client_send_tagline(cmd, "NO Allocating mailbox failed."); return true; } } bool warn_maxsize = false, warn_toomany = false, warn_noprivate = false; if (args[1].type == IMAP_ARG_LIST) { // entries const struct imap_arg *arglist = NULL; if (!imap_arg_get_list(&args[1], &arglist)){ client_send_command_error(cmd, "Cannot read entries, list expected."); mailbox_free(&box); return true; } while (arglist[0].type != IMAP_ARG_EOL) { if (!IMAP_ARG_TYPE_IS_ASTRING(arglist[0].type)) { client_send_command_error(cmd, "Entry name not a string."); mailbox_free(&box); return true; } const char *name = NULL; if (!imap_arg_get_astring(&arglist[0], &name)){ client_send_command_error(cmd, "Cannot read entry name, string expected."); mailbox_free(&box); return true; } if (name == NULL) { client_send_tagline(cmd, "NO Entry name is NULL."); mailbox_free(&box); return true; } const char *value; if (arglist[1].type == IMAP_ARG_NIL) { value = NULL; } else if (IMAP_ARG_TYPE_IS_ASTRING(arglist[1].type)) { if (!imap_arg_get_astring(&arglist[1], &value)){ client_send_command_error(cmd, "Cannot read value, string expected."); mailbox_free(&box); return true; } } else { client_send_command_error(cmd, "Value not nil or string."); mailbox_free(&box); return true; } struct metadata_entry *entry = parse_entry(box, name, value); if (entry == NULL) { client_send_tagline(cmd, "NO Parsing entry failed."); mailbox_free(&box); return true; } int ret = metadata_set_entry(entry, cmd->client->user); if (ret == -2) { warn_maxsize = true; } else if (ret == -3) { warn_toomany = true; } else if (ret < 0) { client_send_tagline(cmd, "NO Setting entry failed."); mailbox_free(&box); return true; } /* skip this name/value pair */ arglist += 2; } } else { client_send_command_error(cmd, "Entries not a list."); mailbox_free(&box); return true; } const char *response; if (warn_maxsize) { struct metadata_mail_user *muser = METADATA_USER_CONTEXT(cmd->client->user); if (muser == NULL) { i_error("metadata: found NULL user, can't set metadata"); client_send_tagline(cmd, "NO Internal error."); mailbox_free(&box); return true; } response = t_strdup_printf("OK [METADATA MAXSIZE %d] Completed.", muser->set->maxsize); } else if (warn_toomany) { response = t_strdup_printf("OK [METADATA TOOMANY] Completed."); } else if (warn_noprivate) { response = t_strdup_printf("OK [METADATA NOPRIVATE] Completed."); } else { response = "OK Completed."; } client_send_tagline(cmd, response); mailbox_free(&box); return true; } static void imap_metadata_client_created(struct client **client) { if (mail_user_is_plugin_loaded((*client)->user, imap_metadata_module)) str_append((*client)->capability_string, " METADATA"); if (next_hook_client_created != NULL) next_hook_client_created(client); } void imap_metadata_plugin_init(struct module *module) { command_register("GETMETADATA", cmd_getmetadata, 0); command_register("SETMETADATA", cmd_setmetadata, 0); imap_metadata_module = module; next_hook_client_created = hook_client_created; hook_client_created = imap_metadata_client_created; } void imap_metadata_plugin_deinit(void) { command_unregister("SETMETADATA"); command_unregister("GETMETADATA"); hook_client_created = next_hook_client_created; } dovecot-metadata-plugin-bdf2445e101f/src/mailbox-ext.c0000644000000000000000000000173311575123055022736 0ustar00usergroup00000000000000/* 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 . */ #include "mailbox-ext.h" #include "hex-binary.h" const char * mailbox_get_guid_string(struct mailbox *box) { uint8_t guid[MAIL_GUID_128_SIZE]; if (mailbox_get_guid(box, guid) < 0) return NULL; return binary_to_hex(guid, sizeof(guid)); } dovecot-metadata-plugin-bdf2445e101f/src/mailbox-ext.h0000644000000000000000000000166011575123055022742 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_MAILBOX_EXT_H #define DOVECOT_MAILBOX_EXT_H #include "metadata-global.h" #include "mail-storage.h" const char * mailbox_get_guid_string(struct mailbox *box) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-backend.c0000644000000000000000000001653011575123055023653 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-backend.h" #include "dict.h" #include "mail-storage.h" #include #include "str-ext.h" #include "dict-ext.h" #include "mailbox-ext.h" #include "metadata-entry-private.h" #include "metadata-mail-user-module-private.h" static const char * dict_subjects[ENTRY_SUBJECT_MAX+1] = { "server/", /* ENTRY_SUBJECT_SERVER */ "mailbox/", /* ENTRY_SUBJECT_MAILBOX */ NULL }; static const char* dictsubject_from_entry(struct metadata_entry *entry) { switch (metadata_entry_get_subject(entry)) { case ENTRY_SUBJECT_SERVER: return dict_subjects[ENTRY_SUBJECT_SERVER]; case ENTRY_SUBJECT_MAILBOX: return t_strconcat(dict_subjects[ENTRY_SUBJECT_MAILBOX], entry->mailbox_guid, "/", NULL); case ENTRY_SUBJECT_MAX: return NULL; } return NULL; } static const char* t_dictkey_from_entry(struct metadata_entry *entry) { const char *subject = dictsubject_from_entry(entry); if (subject == NULL) return NULL; const char *path_prefix = NULL; switch (metadata_entry_get_scope(entry)) { case ENTRY_SCOPE_SHARED: path_prefix = DICT_PATH_SHARED; break; case ENTRY_SCOPE_PRIVATE: path_prefix = DICT_PATH_PRIVATE; break; case ENTRY_SCOPE_INVALID: case ENTRY_SCOPE_NONE: return NULL; } // -> "prefix/" "subject/" "name" return t_strconcat(path_prefix, subject, &entry->name[1], NULL); } static int count_entries(struct metadata_mail_user *muser) { struct dict_iterate_context *iter; const char *key; const char *value; int num = 0; iter = dict_iterate_init(muser->dict, DICT_PATH_SHARED, DICT_ITERATE_FLAG_RECURSE); while (dict_iterate(iter, &key, &value)) { num++; } if (dict_iterate_deinit(&iter) < 0) { i_error("metadata: dict iteration failed, can't count shared entries"); return -1; } iter = dict_iterate_init(muser->dict, DICT_PATH_PRIVATE, DICT_ITERATE_FLAG_RECURSE); while (dict_iterate(iter, &key, &value)) { num++; } if (dict_iterate_deinit(&iter) < 0) { i_error("metadata: dict iteration failed, can't count private entries"); return -1; } return num; } int metadata_set_entry(struct metadata_entry *entry, struct mail_user *user) { struct metadata_mail_user *muser = METADATA_USER_CONTEXT(user); if (muser == NULL) { i_error("metadata: found NULL user, can't set their metadata"); return -1; } if (!metadata_entry_is_valid(entry)) return -4; if (strlen(entry->name) > muser->set->maxsize) return -2; if (count_entries(muser) > muser->set->maxentries) return -3; const char *key = t_dictkey_from_entry(entry); if (key == NULL) return -1; struct dict_transaction_context *dt = dict_transaction_begin(muser->dict); if (entry->value == NULL) dict_unset(dt, key); else dict_set(dt, key, entry->value); if (dict_transaction_commit(&dt) < 0) { i_error("metadata: dict commit failed"); return -1; } return 0; } int metadata_get_entry(struct metadata_entry *entry, struct mail_user *user) { struct metadata_mail_user *muser = METADATA_USER_CONTEXT(user); if (muser == NULL) { i_error("metadata: found NULL user, can't get their metadata"); return -1; } if (!metadata_entry_is_valid(entry)) return -4; const char *key = t_dictkey_from_entry(entry); if (key == NULL) return -1; return dict_lookup(muser->dict, user->pool, key, &entry->value); } struct metadata_iterate_context { struct dict_iterate_multiscope_context *dict_ctx; int depth; bool failed; }; struct metadata_iterate_context* metadata_iterate_init(struct mailbox *mailbox, struct metadata_entry *entry, int depth) { struct metadata_iterate_context *ctx = i_new(struct metadata_iterate_context, 1); memset(ctx, 0, sizeof(*ctx)); struct mail_storage *storage = mailbox_get_storage(mailbox); struct mail_user *user = mail_storage_get_user(storage); struct metadata_mail_user *muser = METADATA_USER_CONTEXT(user); if (muser == NULL) { i_error("metadata: found NULL user, can't iterate over their metadata"); ctx->failed = true; return ctx; } i_assert(entry != NULL); if (entry == NULL) { ctx->failed = true; return ctx; } const char *entry_name = metadata_entry_get_name(entry); const int root_depth = strchr_num(entry_name, '/'); ctx->depth = root_depth + depth; enum dict_iterate_multiscope_flags flags = 0; if (depth != 0) flags |= DICT_ITERATE_FLAG_RECURSE; switch (metadata_entry_get_scope(entry)) { case ENTRY_SCOPE_SHARED: case ENTRY_SCOPE_PRIVATE: break; case ENTRY_SCOPE_INVALID: ctx->failed = true; return ctx; case ENTRY_SCOPE_NONE: flags |= DICT_ITERATE_MULTISCOPE_FLAG_MULTISCOPE; break; } const char *key = t_dictkey_from_entry(entry); if (key == NULL) { ctx->failed = true; return ctx; } ctx->dict_ctx = dict_iterate_multiscope_init(muser->dict, key, flags); if (ctx->dict_ctx == NULL) { ctx->failed = true; return ctx; } return ctx; } static ATTR_NONNULL(2) const char * entry_name_from_dict_name(enum metadata_entry_subject subject, const char *dict_name) { /* skip dict internal prefixes: priv/ or shared/ */ const char *name_after_scope = strchr(dict_name, '/'); if (name_after_scope == NULL) { return NULL; } /* skip '/' */ name_after_scope++; /* skip dict internal prefixes: server/ or mailbox/ */ const char *name_after_subject = strchr(name_after_scope, '/'); if (name_after_subject == NULL) { return NULL; } /* do not skip '/', the name needs to start with a '/'! */ /* skip dict internal prefixes: / (for mailboxes only) */ if (subject == ENTRY_SUBJECT_MAILBOX) { name_after_subject = strchr(name_after_subject+1, '/'); if (name_after_subject == NULL) { return NULL; } } return name_after_subject; } bool metadata_iterate(struct metadata_iterate_context *ctx, struct metadata_entry *entry) { i_assert(ctx != NULL); if (ctx == NULL) return false; if (ctx->failed) return false; entry->name = NULL; while (entry->name == NULL) { const char *dict_name = NULL, *dict_value = NULL; if (!dict_iterate_multiscope(ctx->dict_ctx, &dict_name, &dict_value)) return false; const char *entry_name = entry_name_from_dict_name(metadata_entry_get_subject(entry), dict_name); if (entry_name == NULL) { ctx->failed = true; return false; } if (ctx->depth != METADATA_ITERATE_DEPTH_INF && strchr_num(entry_name, '/') > ctx->depth) continue; entry->name = i_strdup(entry_name); entry->value = i_strdup(dict_value); } return true; } int metadata_iterate_deinit(struct metadata_iterate_context **ctx) { i_assert(ctx != NULL); if (ctx == NULL) return -1; i_assert(*ctx != NULL); if (*ctx == NULL) return -1; int ret = (*ctx)->failed ? -1 : 0; if ((*ctx)->dict_ctx != NULL && dict_iterate_multiscope_deinit(&(*ctx)->dict_ctx) < 0) ret = -1; i_free(*ctx); return ret; } dovecot-metadata-plugin-bdf2445e101f/src/metadata-backend.h0000644000000000000000000000275511575123055023664 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_BACKEND_H #define DOVECOT_METADATA_BACKEND_H #include "metadata-global.h" #include #include "metadata-entry.h" int metadata_get_entry(struct metadata_entry *entry, struct mail_user *user) ATTR_NONNULL(1,2); int metadata_set_entry(struct metadata_entry *entry, struct mail_user *user) ATTR_NONNULL(1,2); const int METADATA_ITERATE_DEPTH_INF = INT_MAX; struct metadata_iterate_context; struct metadata_iterate_context * metadata_iterate_init(struct mailbox *mailbox, struct metadata_entry *entry, int depth) ATTR_NONNULL(1,2); bool metadata_iterate(struct metadata_iterate_context *ctx, struct metadata_entry *entry) ATTR_NONNULL(1,2); int metadata_iterate_deinit(struct metadata_iterate_context **ctx) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-entry-private.h0000644000000000000000000000204011575123055025071 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_ENTRY_PRIVATE_H #define DOVECOT_METADATA_ENTRY_PRIVATE_H #include "metadata-entry.h" struct metadata_entry { enum metadata_entry_scope scope; enum metadata_entry_type type; const char *mailbox_guid; // implicitly defines the subject! const char *name; const char *value; }; #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-entry.c0000644000000000000000000000770311575123055023427 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-entry-private.h" #include #include #include "mailbox-ext.h" static const char * entry_scopes[ENTRY_SCOPE_MAX+1] = { "private/", /* ENTRY_SCOPE_PRIVATE */ "shared/", /* ENTRY_SCOPE_SHARED */ NULL }; static enum metadata_entry_scope parse_scope(const char *name) { if (name == NULL) return ENTRY_SCOPE_INVALID; /* scope must be empty or begin with '/' */ if (name[0] != '/') { if (name[0] == '\0') return ENTRY_SCOPE_NONE; return ENTRY_SCOPE_INVALID; } /* skip '/' */ name++; /* scope is the first component */ for (int i = 0; i < ENTRY_SCOPE_MAX; i++) { if (strncasecmp(entry_scopes[i], name, strlen(entry_scopes[i])) == 0) return i; } return ENTRY_SCOPE_INVALID; } static const char * entry_types[ENTRY_TYPE_MAX+1] = { "vendor/", /* ENTRY_TYPE_VENDOR */ "", /* ENTRY_TYPE_RFC */ NULL }; static enum metadata_entry_type parse_type(const char *name) { /* lazy evaluation of scope existance */ if (name == NULL || *name++ != '/') return ENTRY_TYPE_INVALID; /* type is the second component */ name = strchr(name, '/'); if (name++ == NULL) return ENTRY_TYPE_NONE; for (int i = 0; i < ENTRY_TYPE_MAX; i++) { if (strncasecmp(entry_types[i], name, strlen(entry_types[i])) == 0) return i; } return ENTRY_TYPE_INVALID; } /* create entry on mailbox with name=value */ struct metadata_entry * metadata_entry_alloc(struct mailbox *mailbox, const char *name, const char *value) { struct metadata_entry *entry = i_new(struct metadata_entry, 1); memset(entry, 0, sizeof(*entry)); if (mailbox != NULL) { const char *mailbox_guid = mailbox_get_guid_string(mailbox); if (mailbox_guid != NULL) entry->mailbox_guid = strdup(mailbox_guid); } entry->scope = parse_scope(name); entry->type = parse_type(name); if (metadata_entry_is_valid(entry)) { if (name != NULL) entry->name = strdup(name); if (value != NULL) entry->value = strdup(value); } return entry; } /* free structures allocated for entry and invalidate it */ void entry_free(struct metadata_entry *entry) { free((char*)entry->value); free((char*)entry->name); memset(entry, 0, sizeof(*entry)); } bool metadata_entry_is_valid(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return false; return entry->scope < ENTRY_SCOPE_MAX && entry->type < ENTRY_TYPE_MAX; } const char * metadata_entry_get_name(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return NULL; return entry->name; } const char * metadata_entry_get_value(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return NULL; return entry->value; } enum metadata_entry_subject metadata_entry_get_subject(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return ENTRY_SUBJECT_INVALID; return entry->mailbox_guid ? ENTRY_SUBJECT_MAILBOX : ENTRY_SUBJECT_SERVER; } enum metadata_entry_scope metadata_entry_get_scope(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return ENTRY_SCOPE_INVALID; return entry->scope; } enum metadata_entry_type metadata_entry_get_type(struct metadata_entry *entry) { i_assert(entry != NULL); if (entry == NULL) return ENTRY_TYPE_INVALID; return entry->type; } dovecot-metadata-plugin-bdf2445e101f/src/metadata-entry.h0000644000000000000000000000407311575123055023431 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_ENTRY_H #define DOVECOT_METADATA_ENTRY_H #include "metadata-global.h" #include #include "mail-storage.h" enum metadata_entry_subject { ENTRY_SUBJECT_SERVER = 0, ENTRY_SUBJECT_MAILBOX = 1, ENTRY_SUBJECT_MAX, ENTRY_SUBJECT_INVALID = ENTRY_SUBJECT_MAX }; enum metadata_entry_scope { ENTRY_SCOPE_PRIVATE = 0, ENTRY_SCOPE_SHARED = 1, ENTRY_SCOPE_MAX, ENTRY_SCOPE_INVALID = ENTRY_SCOPE_MAX, ENTRY_SCOPE_NONE }; enum metadata_entry_type { ENTRY_TYPE_VENDOR = 0, ENTRY_TYPE_RFC = 1, ENTRY_TYPE_MAX, ENTRY_TYPE_INVALID = ENTRY_TYPE_MAX, ENTRY_TYPE_NONE }; struct metadata_entry * metadata_entry_alloc(struct mailbox *mailbox, const char *name, const char *value) ATTR_NONNULL(2); void metadata_entry_free(struct metadata_entry *entry) ATTR_NONNULL(1); bool metadata_entry_is_valid(struct metadata_entry *entry) ATTR_NONNULL(1); const char * metadata_entry_get_name(struct metadata_entry *entry) ATTR_NONNULL(1); const char * metadata_entry_get_value(struct metadata_entry *entry) ATTR_NONNULL(1); enum metadata_entry_subject metadata_entry_get_subject(struct metadata_entry *entry) ATTR_NONNULL(1); enum metadata_entry_scope metadata_entry_get_scope(struct metadata_entry *entry) ATTR_NONNULL(1); enum metadata_entry_type metadata_entry_get_type(struct metadata_entry *entry) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-global.h0000644000000000000000000000303411575123055023524 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_GLOBAL_H #define DOVECOT_METADATA_GLOBAL_H /* the dovecot include system needs its own special care: * include lib.h first, always * reset all the symbols we use by including metadata-config.h.in, since dovecot's internal config.h leaks through their public headers */ #include "lib.h" #define ATTR_NONNULL(...) __attribute__((__nonnull__(__VA_ARGS__))) /* = error values = < 0 is always an error 0 means success or no-more-data > 0 means more-data-available = return types = void can never have errors == logical functions == return bool and cannot have errors == functions returning pointers == NULL is an error, everything else not == data handling functions == bool is a continous function which cannot have errors int is any function which can have errors */ #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-mail-storage-module.c0000644000000000000000000000576511575123055026143 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-mail-storage-module.h" #include "dict.h" #include "module-context.h" #include "mail-storage-private.h" #include "mailbox-ext.h" #include "metadata-mail-user-module-private.h" #define METADATA_MAILBOX_CONTEXT(obj) MODULE_CONTEXT(obj, metadata_mailbox_module) static MODULE_CONTEXT_DEFINE_INIT(metadata_mailbox_module, &mail_storage_module_register); static int metadata_mailbox_delete(struct mailbox *box) { union mailbox_module_context *mbox = METADATA_MAILBOX_CONTEXT(box); if (mbox == NULL) { i_error("metadata: found NULL mailbox, can't delete it"); return -1; } struct mail_storage *storage = mailbox_get_storage(box); struct mail_user *user = mail_storage_get_user(storage); struct metadata_mail_user *muser = METADATA_USER_CONTEXT(user); if (muser == NULL) { i_error("metadata: found NULL user, can't delete mailbox"); return -1; } struct dict_transaction_context *dt = dict_transaction_begin(muser->dict); const char *name; const char *value; const char *skey = t_strconcat(DICT_PATH_SHARED, mailbox_get_guid_string(box), NULL); struct dict_iterate_context *siter = dict_iterate_init(muser->dict, skey, DICT_ITERATE_FLAG_RECURSE); while (dict_iterate(siter, &name, &value)) { dict_unset(dt, name); } if (dict_iterate_deinit(&siter) < 0) { i_error("metadata: dict iteration (" DICT_PATH_SHARED ") failed, can't update dict"); return -1; } const char *pkey = t_strconcat(DICT_PATH_PRIVATE, mailbox_get_guid_string(box), NULL); struct dict_iterate_context *piter = dict_iterate_init(muser->dict, pkey, DICT_ITERATE_FLAG_RECURSE); while (dict_iterate(piter, &name, &value)) { dict_unset(dt, name); } if (dict_iterate_deinit(&piter) < 0) { i_error("metadata: dict iteration (" DICT_PATH_PRIVATE ") failed, can't update dict"); return -1; } int super_ret = mbox->super.delete(box); if (super_ret < 0) { dict_transaction_rollback(&dt); } else if (dict_transaction_commit(&dt) < 0) { i_error("metadata: dict commit failed"); return -1; } return super_ret; } void metadata_mailbox_allocated(struct mailbox *box) { union mailbox_module_context *mbox = p_new(box->pool, union mailbox_module_context, 1); mbox->super = box->v; box->v.delete = metadata_mailbox_delete; MODULE_CONTEXT_SET_SELF(box, metadata_mailbox_module, mbox); } dovecot-metadata-plugin-bdf2445e101f/src/metadata-mail-storage-module.h0000644000000000000000000000167411575123055026143 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_MAIL_STORAGE_MODULE_H #define DOVECOT_METADATA_MAIL_STORAGE_MODULE_H #include "metadata-global.h" #include "mail-storage.h" void metadata_mailbox_allocated(struct mailbox *box); #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-mail-user-module-private.h0000644000000000000000000000241511575123055027117 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_MAIL_USER_MODULE_PRIVATE_H #define DOVECOT_METADATA_MAIL_USER_MODULE_PRIVATE_H #include "metadata-mail-user-module.h" #include "dict.h" #include "module-context.h" #include "mail-user.h" #include "metadata-settings.h" #define METADATA_USER_CONTEXT(obj) MODULE_CONTEXT(obj, metadata_mail_user_module) extern MODULE_CONTEXT_DEFINE(metadata_mail_user_module, &mail_user_module_register); struct metadata_mail_user { union mail_user_module_context module_ctx; struct dict *dict; struct metadata_settings *set; }; #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-mail-user-module.c0000644000000000000000000000353411575123055025445 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-mail-user-module-private.h" struct metadata_mail_user_module metadata_mail_user_module = MODULE_CONTEXT_INIT(&mail_user_module_register); static void metadata_mail_user_deinit(struct mail_user *user) { struct metadata_mail_user *muser = METADATA_USER_CONTEXT(user); if (muser == NULL) { i_error("metadata: found NULL user, can't deinit it"); return; } if (muser->dict != NULL) { dict_deinit(&muser->dict); } if (muser->set != NULL) { metadata_settings_deinit(&muser->set); } return muser->module_ctx.super.deinit(user); } void metadata_mail_user_created(struct mail_user *user) { struct metadata_mail_user *muser = p_new(user->pool, struct metadata_mail_user, 1); muser->module_ctx.super = user->v; user->v.deinit = metadata_mail_user_deinit; metadata_settings_init(&muser->set, user); if (muser->set->dict_uri != NULL) { muser->dict = dict_init(muser->set->dict_uri, DICT_DATA_TYPE_STRING, user->username, user->set->base_dir); if (muser->dict == NULL) i_error("metadata: dict_init(%s) failed", muser->set->dict_uri); } MODULE_CONTEXT_SET(user, metadata_mail_user_module, muser); } dovecot-metadata-plugin-bdf2445e101f/src/metadata-mail-user-module.h0000644000000000000000000000166611575123055025456 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_MAIL_USER_MODULE_H #define DOVECOT_METADATA_MAIL_USER_MODULE_H #include "metadata-global.h" #include "mail-user.h" void metadata_mail_user_created(struct mail_user *user); #endif dovecot-metadata-plugin-bdf2445e101f/src/metadata-plugin.c0000644000000000000000000000245411575123055023562 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-global.h" #include "mail-storage-hooks.h" #include "metadata-mail-user-module.h" #include "metadata-mail-storage-module.h" const char *metadata_plugin_version = DOVECOT_VERSION; static struct mail_storage_hooks metadata_mail_storage_hooks = { .mail_user_created = metadata_mail_user_created, .mailbox_allocated = metadata_mailbox_allocated }; void metadata_plugin_init(struct module *module) { mail_storage_hooks_add(module, &metadata_mail_storage_hooks); } void metadata_plugin_deinit(void) { mail_storage_hooks_remove(&metadata_mail_storage_hooks); } dovecot-metadata-plugin-bdf2445e101f/src/metadata-settings.c0000644000000000000000000000514711575123055024126 0ustar00usergroup00000000000000/* 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 . */ #include "metadata-settings.h" #include #define METADATA_MAXSIZE_DEFAULT 1024 #define METADATA_MAXENTRIES_DEFAULT 65336 void metadata_settings_init(struct metadata_settings **set, struct mail_user *user) { *set = i_new(struct metadata_settings, 1); memset(*set, 0, sizeof(**set)); const char *dict_uri = mail_user_plugin_getenv(user, "metadata_dict"); if (dict_uri != NULL) { (*set)->dict_uri = dict_uri; } else if (user->mail_debug) { i_debug("metadata: No metadata_dict setting - " "metadata storage is disabled"); (*set)->dict_uri = NULL; } const char *maxsize = mail_user_plugin_getenv(user, "metadata_maxsize"); if (maxsize != NULL) { (*set)->maxsize = strtol(maxsize, NULL, 10); if ((*set)->maxsize < 0 || (*set)->maxsize == LONG_MAX) { if (user->mail_debug) { i_debug("metadata: Illegal metadata_maxsize setting - " "using default of %d", METADATA_MAXSIZE_DEFAULT); } (*set)->maxsize = METADATA_MAXSIZE_DEFAULT; } } else { if (user->mail_debug) { i_debug("metadata: No metadata_maxsize setting - " "using default of %d", METADATA_MAXSIZE_DEFAULT); } (*set)->maxsize = METADATA_MAXSIZE_DEFAULT; } const char *maxentries = mail_user_plugin_getenv(user, "metadata_maxentries"); if (maxentries != NULL) { (*set)->maxentries = strtol(maxentries, NULL, 10); if ((*set)->maxentries < 0 || (*set)->maxentries == LONG_MAX) { if (user->mail_debug) { i_debug("metadata: Illegal metadata_maxentries setting - " "using default of %d", METADATA_MAXENTRIES_DEFAULT); } (*set)->maxentries = METADATA_MAXENTRIES_DEFAULT; } } else { if (user->mail_debug) { i_debug("metadata: No metadata_maxentries setting - " "using default of %d", METADATA_MAXENTRIES_DEFAULT); } (*set)->maxentries = METADATA_MAXENTRIES_DEFAULT; } } void metadata_settings_deinit(struct metadata_settings **set) { free(*set); *set = NULL; } dovecot-metadata-plugin-bdf2445e101f/src/metadata-settings.h0000644000000000000000000000222011575123055024120 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_METADATA_SETTINGS_H #define DOVECOT_METADATA_SETTINGS_H #include "metadata-global.h" #include "mail-user.h" struct metadata_settings { bool metadata_debug; const char *dict_uri; int maxsize; int maxentries; }; void metadata_settings_init(struct metadata_settings **set, struct mail_user *user) ATTR_NONNULL(1,2); void metadata_settings_deinit(struct metadata_settings **set) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/src/str-ext.c0000644000000000000000000000204611575123055022111 0ustar00usergroup00000000000000/* 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 . */ #include "str-ext.h" #include int strchr_num(const char *s, int c) { int num = 0; s = strchr(s, c); while (s != NULL) { num++; s = strchr(s+1, c); } return num; } bool str_has_wildcards(const char *s) { for (; *s != '\0'; s++) { if (*s == '*' || *s == '%') return TRUE; } return FALSE; } dovecot-metadata-plugin-bdf2445e101f/src/str-ext.h0000644000000000000000000000200011575123055022104 0ustar00usergroup00000000000000/* 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 . */ #ifndef DOVECOT_STR_EXT_H #define DOVECOT_STR_EXT_H #include "metadata-global.h" #include #include "str.h" #define str_append_printf str_printfa int strchr_num(const char *s, int c) ATTR_NONNULL(1); bool str_has_wildcards(const char *s) ATTR_NONNULL(1); #endif dovecot-metadata-plugin-bdf2445e101f/test/imapsupport.py0000644000000000000000000001064411575123055023467 0ustar00usergroup00000000000000# Copyright (C) 2008 by Intevation GmbH # Authors: # Bernhard Herzog # # This program is free software under the LGPL (>=v2.1) # Read the file COPYING coming with the software for details. import os import imaplib import ConfigParser def convert_bool(s): s = s.lower() if s in ("true", "yes", "1"): return True if s in ("false", "no", "0"): return False raise ValueError("cannot determine boolean value of %r" % (s,)) class ImapConfig(object): def __init__(self, configfile): parser = ConfigParser.SafeConfigParser() parser.read([configfile]) for name, conv in [("host", str), ("port", int), ("login", str), ("password", str), ("ssl", convert_bool)]: setattr(self, name, conv(parser.get("imap", name))) default_config_file = os.path.join(os.path.dirname(__file__), "imaptest.conf") def default_config(): return ImapConfig(default_config_file) class AnnotationsMixin: def install_commands_in_imaplib(self): imaplib.Commands['GETANNOTATION'] = ('AUTH', 'SELECTED') imaplib.Commands['SETANNOTATION'] = ('AUTH', 'SELECTED') def to_argument_string(self, arg): if isinstance(arg, basestring): return self._quote(arg) elif arg is None: return "NIL" else: return "(%s)" % (" ".join(self.to_argument_string(item) for item in arg),) def getannotation(self, *args): # normally we would implement this command like the other # commands in IMAP with an explicit list of parameters. For # tests it's useful to be able to omit parameters or to send too # many, so we allow an arbitrary number of parameters self.install_commands_in_imaplib() args = tuple(self.to_argument_string(item) for item in args) typ, dat = self._simple_command('GETANNOTATION', *args) return self._untagged_response(typ, dat, 'ANNOTATION') def setannotation(self, *args): # normally we would implement this command like the other # commands in IMAP with an explicit list of parameters. For # tests it's useful to be able to omit parameters or to send too # many, so we allow an arbitrary number of parameters self.install_commands_in_imaplib() args = tuple(self.to_argument_string(item) for item in args) return self._simple_command('SETANNOTATION', *args) class IMAP4_annotations(imaplib.IMAP4, AnnotationsMixin): pass class IMAP4_SSL_annotations(imaplib.IMAP4_SSL, AnnotationsMixin): pass class ImapError(Exception): def __init__(self, host, port, imap_result): Exception.__init__(self, "Unexpected response from imap server" " (%r:%d):%r" % (host, port, imap_result)) self.imap_result = imap_result class ImapConnection(object): def __init__(self, host, port, login, password, use_ssl): self.host = host self.port = port if use_ssl: cls = IMAP4_SSL_annotations else: cls = IMAP4_annotations self.error_class = cls.error self.imap = cls(host, port) self.auth_plain(login, password) def check_res(self, res, ok_responses=("OK",)): assert len(res) == 2 if res[0] not in ok_responses: raise ImapError(self.host, self.port, res) data = res[1] # for some reason imaplib uses a one-element list containing # None to indicate that no untagged responses came from the # server. Translate this to an empty list. if data == [None]: data = [] return data def auth_plain(self, login, password): self.check_res(self.imap.login(login, password)) def logout(self): self.check_res(self.imap.logout(), ok_responses=("OK", "BYE")) @property def capabilities(self): return self.imap.capabilities def create(self, mailbox): self.check_res(self.imap.create(mailbox)) def delete(self, mailbox): self.check_res(self.imap.delete(mailbox)) def rename(self, oldmailbox, newmailbox): self.check_res(self.imap.rename(oldmailbox, newmailbox)) def getannotation(self, *args): return self.check_res(self.imap.getannotation(*args)) def setannotation(self, *args): return self.check_res(self.imap.setannotation(*args)) dovecot-metadata-plugin-bdf2445e101f/test/imaptest-example.conf0000644000000000000000000000026511575123055024656 0ustar00usergroup00000000000000# example configuration for the test suite. Rename to imaptest.conf and # adapt to your needs. [imap] host = localhost port = 143 ssl = False login = testuser password = secret dovecot-metadata-plugin-bdf2445e101f/test/runtests.py0000644000000000000000000000473611575123055023000 0ustar00usergroup00000000000000#! /usr/bin/env python # Copyright (C) 2004, 2005, 2006, 2007, 2008 by Intevation GmbH # Authors: # Bernhard Herzog # # This program is free software under the LGPL (>=v2.1) # Read the file COPYING coming with the software for details. """ Main entry point for the test suite. Just run this file as a python script to execute all tests """ import os import sys import unittest import optparse test_dir = os.path.dirname(__file__) sys.path.append(os.path.join(test_dir, os.pardir)) def find_test_modules(dirname, package = None): """Return a list the names of the test modules in the directory dirname The return value is a list of names that can be passed to unittest.defaultTestLoader.loadTestsFromNames. Each name of the list is the name of a pure python module, one for each file in dirname whose name starts with 'test' and ends with '.py'. The optional parameter package should be the name of the python package whose directory is dirname. If package is given all names in the returned list will be prefixed with package and a dot. """ if package: prefix = package + "." else: prefix = "" suffix = ".py" return [prefix + name[:-len(suffix)] for name in os.listdir(dirname) if name.startswith("test") and name.endswith(suffix)] def main(): """Run all the tests in the test suite""" parser = optparse.OptionParser() parser.set_defaults(verbosity=1, test_private_metadata=False) parser.add_option("-v", "--verbose", action="store_const", const=2, dest="verbosity") parser.add_option("--test-private-metadata", action="store_const", const=True) parser.add_option("--config") opts, rest = parser.parse_args() if opts.config is not None: import imapsupport imapsupport.default_config_file = opts.config # Build the list of test names. If names were given on the command # line, run exactly those. Othwerwise build a default list of # names. if rest: names = rest else: names = find_test_modules(test_dir) if not opts.test_private_metadata: names = [name for name in names if not name.endswith("_private")] suite = unittest.defaultTestLoader.loadTestsFromNames(names) runner = unittest.TextTestRunner(verbosity=opts.verbosity) result = runner.run(suite) sys.exit(not result.wasSuccessful()) if __name__ == "__main__": main() dovecot-metadata-plugin-bdf2445e101f/test/test_annotatemore.py0000644000000000000000000004342611575123055024643 0ustar00usergroup00000000000000# Copyright (C) 2008 by Intevation GmbH # Authors: # Bernhard Herzog # # This program is free software under the LGPL (>=v2.1) # Read the file COPYING coming with the software for details. import unittest from imapsupport import ImapConnection, ImapError, default_config class AnnotationTests(unittest.TestCase): def setUp(self): self.config = default_config() self.imap = ImapConnection(self.config.host, self.config.port, self.config.login, self.config.password, self.config.ssl) def tearDown(self): self.imap.logout() def ensure_mailbox_unknown(self, mailbox): try: self.imap.delete(mailbox) except ImapError: pass def ensure_mailbox_new_and_empty(self, mailbox): self.ensure_mailbox_unknown(mailbox) self.imap.create(mailbox) def check_bad_parameters(self, command, args, message_template): try: getattr(self.imap, command.lower())(*args) except self.imap.error_class, e: self.failUnless(str(e).startswith("%s command error: BAD" % command.upper())) else: self.fail(message_template % command.upper()) def check_imap_error(self, command, args, message_template, response_type="NO", response=None): try: getattr(self.imap, command.lower())(*args) except ImapError, e: self.failUnless(e.imap_result[0] == response_type) if response: self.failUnless(response in e.imap_result[1]) else: self.fail(message_template % command.upper()) class TestCapabilities(AnnotationTests): def test_capabilities(self): self.failUnless("ANNOTATEMORE" in self.imap.capabilities) class TestGetAnnotation(AnnotationTests): def setUp(self): AnnotationTests.setUp(self) self.mailbox = "INBOX" self.entry = "/vendor/kolab/folder-type" self.attribute = "value.shared" def test_getannotation_no_parameters(self): self.check_bad_parameters("GETANNOTATION", (), "%s without parameters did not return an" " error") def test_getannotation_one_parameters(self): self.check_bad_parameters("GETANNOTATION", ("INBOX",), "%s with only one parameter did not return an" " error") def test_getannotation_two_parameters(self): self.check_bad_parameters("GETANNOTATION", ("INBOX", "/vendor/kolab/test"), "%s with two parameters did not return an" " error") def test_getannotation_entry_no_slash(self): self.check_bad_parameters("GETANNOTATION", ("INBOX", "comment", "value.shared"), "%s with entry not starting with slash" " did not return an error") def test_getannotation_attribute_nil(self): self.check_bad_parameters("GETANNOTATION", (self.mailbox, self.entry, None), "%s with attribute name NIL did not return" " an error") def test_getannotation_nonexisting_mailbox(self): mailbox = "INBOX/nowhere" # make sure mailbox doesn't exist self.ensure_mailbox_unknown(mailbox) self.check_imap_error("GETANNOTATION", (mailbox, "/comment", "value.shared"), "%s for non-existing mailbox did not" " return an error") def test_getannotation_unknown_namespace(self): mailbox = "unknown/foo" # make sure mailbox doesn't exist self.ensure_mailbox_unknown(mailbox) self.check_imap_error("GETANNOTATION", (mailbox, "/comment", ("value.shared", "foo")), "%s for unknown mailbox namespace did not" " return an error") def test_getannotation(self): annotation = self.imap.getannotation("INBOX", "/vendor/kolab/test", "value.shared") self.assertEquals(annotation, []) def test_getannotation_lists_wuth_single_elements(self): mailbox = "INBOX/annotated" entry = "/vendor/kolab/test" self.ensure_mailbox_new_and_empty(mailbox) self.imap.setannotation(mailbox, entry, ["value.shared", "an annotation"]) annotation = self.imap.getannotation(mailbox, [entry], ["value.shared"]) self.assertEquals(annotation, ['"INBOX/annotated" "/vendor/kolab/test"' ' ("value.shared" "an annotation")']) class TestSetAnnotation(AnnotationTests): def setUp(self): AnnotationTests.setUp(self) self.mailbox = "INBOX/Calendar" self.entry = "/vendor/kolab/folder-type" self.attribute = "value.shared" self.value = "event" self.ensure_mailbox_new_and_empty(self.mailbox) def test_setannotation_no_argument(self): self.check_bad_parameters("SETANNOTATION", (), "%s with no parameters did not return an" " error") def test_setannotation_one_argument(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox), "%s with one parameter did not return an" " error") def test_setannotation_two_argument(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry), "%s with two parameters did not return an" " error") def test_setannotation_entry_no_slash(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, "comment", [self.attribute, self.value]), "%s with entry not starting with slash" " did not return an error") def test_setannotation_attribute_no_list(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, self.attribute), "%s with two parameters did not return an" " error") def test_setannotation_attribute_odd_list(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, ["folder-type", "mail", "entry"]), "%s with two parameters did not return an" " error") def test_setannotation_attribute_empty_list(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, []), "%s with empty attribute list did not return" " an error") def test_setannotation_attribute_nil(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, [None, "event"]), "%s with attribute name NIL did not return" " an error") def test_setannotation_attribute_without_period(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, ["folder-type", "mail"]), "%s with attribute without period did not" " return an error") def test_setannotation_attribute_not_ending_in_priv_or_shared(self): self.check_bad_parameters("SETANNOTATION", (self.mailbox, self.entry, ["value.type", "mail"]), "%s with attribute not ending in priv or" " shared did not return an error") def test_setannotation_nonexisting_mailbox(self): mailbox = "INBOX/nowhere" self.ensure_mailbox_unknown(mailbox) self.check_imap_error("SETANNOTATION", (mailbox, "/comment", ("value.shared", "foo")), "%s for non-existing mailbox did not" " return an error") def test_setannotation_unknown_namespace(self): mailbox = "unknown/foo" self.ensure_mailbox_unknown(mailbox) self.check_imap_error("SETANNOTATION", (mailbox, "/comment", ("value.shared", "foo")), "%s for unknown mailbox namespace did not" " return an error") def test_setannotation_public(self): self.imap.setannotation(self.mailbox, self.entry, [self.attribute, self.value]) annotation = self.imap.getannotation(self.mailbox, self.entry, self.attribute) self.assertEquals(annotation, ['"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, self.attribute, self.value)]) def test_setannotation_deleting_public(self): self.imap.setannotation(self.mailbox, self.entry, [self.attribute, self.value]) self.imap.setannotation(self.mailbox, self.entry, [self.attribute, None]) self.assertEquals(self.imap.getannotation(self.mailbox, self.entry, self.attribute), []) class TestMailboxChanges(AnnotationTests): def test_mailbox_renaming(self): self.ensure_mailbox_unknown("INBOX/old") self.ensure_mailbox_unknown("INBOX/new") self.imap.create("INBOX/old") self.imap.setannotation("INBOX/old", "/vendor/kolab/folder-test", ["value.shared", "some value"]) self.imap.rename("INBOX/old", "INBOX/new") self.assertEquals(self.imap.getannotation("INBOX/new", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/new" "/vendor/kolab/folder-test"' ' ("value.shared" "some value")']) def test_mailbox_renaming_with_inferior_mailboxes(self): self.ensure_mailbox_new_and_empty("INBOX/this") self.ensure_mailbox_new_and_empty("INBOX/this/child") self.ensure_mailbox_new_and_empty("INBOX/this/child/grandchild") self.ensure_mailbox_unknown("INBOX/that") self.ensure_mailbox_unknown("INBOX/that/child") self.ensure_mailbox_unknown("INBOX/that/child/grandchild") self.imap.setannotation("INBOX/this/child", "/vendor/kolab/folder-test", ["value.shared", "child value"]) self.imap.setannotation("INBOX/this/child/grandchild", "/vendor/kolab/folder-test", ["value.shared", "grand child value"]) self.imap.rename("INBOX/this", "INBOX/that") self.assertEquals(self.imap.getannotation("INBOX/that/child", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/that/child" "/vendor/kolab/folder-test"' ' ("value.shared" "child value")']) self.assertEquals(self.imap.getannotation("INBOX/that/child/grandchild", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/that/child/grandchild"' ' "/vendor/kolab/folder-test"' ' ("value.shared" "grand child value")']) def test_mailbox_renaming_with_common_prefixes(self): self.ensure_mailbox_new_and_empty("INBOX/this") self.ensure_mailbox_new_and_empty("INBOX/this/child") self.ensure_mailbox_new_and_empty("INBOX/thisother") self.ensure_mailbox_new_and_empty("INBOX/thisother/child") self.ensure_mailbox_unknown("INBOX/that") self.ensure_mailbox_unknown("INBOX/that/child") self.imap.setannotation("INBOX/this/child", "/vendor/kolab/folder-test", ["value.shared", "this child value"]) self.imap.setannotation("INBOX/thisother/child", "/vendor/kolab/folder-test", ["value.shared", "other child value"]) self.imap.rename("INBOX/this", "INBOX/that") self.assertEquals(self.imap.getannotation("INBOX/that/child", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/that/child" "/vendor/kolab/folder-test"' ' ("value.shared" "this child value")']) self.assertEquals(self.imap.getannotation("INBOX/thisother/child", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/thisother/child"' ' "/vendor/kolab/folder-test"' ' ("value.shared" "other child value")']) def test_mailbox_deletion(self): self.ensure_mailbox_new_and_empty("INBOX/deletiontest") self.imap.setannotation("INBOX/deletiontest", "/vendor/kolab/folder-test", ["value.shared", "some value"]) self.assertEquals(self.imap.getannotation("INBOX/deletiontest", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/deletiontest" "/vendor/kolab/folder-test"' ' ("value.shared" "some value")']) self.imap.delete("INBOX/deletiontest") self.imap.create("INBOX/deletiontest") self.assertEquals(self.imap.getannotation("INBOX/deletiontest", "/vendor/kolab/folder-test", "value.shared"), []) def test_mailbox_deletion_with_common_prefixes(self): self.ensure_mailbox_new_and_empty("INBOX/deletiontest") self.ensure_mailbox_new_and_empty("INBOX/deletiontestother") self.imap.setannotation("INBOX/deletiontest", "/vendor/kolab/folder-test", ["value.shared", "some value"]) self.imap.setannotation("INBOX/deletiontestother", "/vendor/kolab/folder-test", ["value.shared", "other value"]) self.imap.delete("INBOX/deletiontest") self.imap.create("INBOX/deletiontest") self.assertEquals(self.imap.getannotation("INBOX/deletiontest", "/vendor/kolab/folder-test", "value.shared"), []) self.assertEquals(self.imap.getannotation("INBOX/deletiontestother", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/deletiontestother"' ' "/vendor/kolab/folder-test"' ' ("value.shared" "other value")']) def test_mailbox_deletion_with_inferior_mailboxes(self): self.ensure_mailbox_new_and_empty("INBOX/deletion") self.ensure_mailbox_new_and_empty("INBOX/deletion/child") self.imap.setannotation("INBOX/deletion/child", "/vendor/kolab/folder-test", ["value.shared", "child value"]) self.imap.delete("INBOX/deletion") self.assertEquals(self.imap.getannotation("INBOX/deletion/child", "/vendor/kolab/folder-test", "value.shared"), ['"INBOX/deletion/child" "/vendor/kolab/folder-test"' ' ("value.shared" "child value")']) def test_renaming_and_deletion_with_large_datasets(self): self.ensure_mailbox_new_and_empty("INBOX/many-annotations") self.ensure_mailbox_unknown("INBOX/many-renamed") value = "x" * 1024 for i in range(1024): entry = "/public/vendor/kolab/numbered_%03d" % i self.imap.setannotation("INBOX/many-annotations", entry, ["value.shared", value]) self.imap.rename("INBOX/many-annotations", "INBOX/many-renamed") for i in range(1024): entry = "/public/vendor/kolab/numbered_%03d" % i self.assertEquals(self.imap.getannotation("INBOX/many-renamed", entry, "value.shared"), ['"INBOX/many-renamed" "%s" ("value.shared" "%s")' % (entry, value)]) self.imap.delete("INBOX/many-renamed") if __name__ == "__main__": unittest.main() dovecot-metadata-plugin-bdf2445e101f/test/test_annotatemore_private.py0000644000000000000000000001001011575123055026354 0ustar00usergroup00000000000000# Copyright (C) 2008 by Intevation GmbH # Authors: # Bernhard Herzog # # This program is free software under the LGPL (>=v2.1) # Read the file COPYING coming with the software for details. import unittest from imapsupport import ImapConnection, ImapError, default_config from test_annotatemore import AnnotationTests class TestSetAnnotation(AnnotationTests): def setUp(self): AnnotationTests.setUp(self) self.mailbox = "INBOX/Calendar" self.entry = "/vendor/kolab/folder-type" self.attribute = "value.shared" self.value = "event" self.ensure_mailbox_new_and_empty(self.mailbox) def test_setannotation_private(self): attribute = "value.priv" value = "private value" self.imap.setannotation(self.mailbox, self.entry, [attribute, value]) annotation = self.imap.getannotation(self.mailbox, self.entry, attribute) self.assertEquals(annotation, ['"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, attribute, value)]) def test_setannotation_deleting_private(self): attribute = "value.priv" value = "private value" self.imap.setannotation(self.mailbox, self.entry, [attribute, value]) self.imap.setannotation(self.mailbox, self.entry, [attribute, None]) annotation = self.imap.getannotation(self.mailbox, self.entry, attribute) self.assertEquals(annotation, []) class TestMisc(AnnotationTests): def setUp(self): AnnotationTests.setUp(self) self.mailbox = "INBOX/Tasks" self.entry = "/vendor/kolab/folder-test" self.attribute = "value" self.attribute_shared = self.attribute + ".shared" self.attribute_private = self.attribute + ".priv" self.value = "task" self.ensure_mailbox_new_and_empty(self.mailbox) def test_public_and_private_are_different_namespaces(self): value_shared = "shared value" value_private = "private value" self.imap.setannotation(self.mailbox, self.entry, [self.attribute_shared, value_shared]) self.imap.setannotation(self.mailbox, self.entry, [self.attribute_private, value_private]) self.assertEquals(self.imap.getannotation(self.mailbox, self.entry, self.attribute_shared), ['"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, self.attribute_shared, value_shared)]) self.assertEquals(self.imap.getannotation(self.mailbox, self.entry, self.attribute_private), ['"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, self.attribute_private, value_private)]) def test_getannotation_attribute_without_suffix(self): value_shared = "shared value" value_private = "private value" self.imap.setannotation(self.mailbox, self.entry, [self.attribute_shared, value_shared]) self.imap.setannotation(self.mailbox, self.entry, [self.attribute_private, value_private]) self.assertEquals(sorted(self.imap.getannotation(self.mailbox, self.entry, self.attribute)), sorted(['"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, self.attribute_shared, value_shared), '"%s" "%s" ("%s" "%s")' % (self.mailbox, self.entry, self.attribute_private, value_private),])) if __name__ == "__main__": unittest.main()