pax_global_header00006660000000000000000000000064122426532760014523gustar00rootroot0000000000000052 comment=7fd247ff4684f934b6006d7915e5803c896e3807 undbx-undbx-0.21/000077500000000000000000000000001224265327600137035ustar00rootroot00000000000000undbx-undbx-0.21/.gitignore000066400000000000000000000001701224265327600156710ustar00rootroot00000000000000.deps/ Makefile Makefile.in aclocal.m4 autom4te.cache/ config.* configure depcomp install-sh missing stamp-h1 *.o undbx undbx-undbx-0.21/COPYING000066400000000000000000001045131224265327600147420ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, 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 them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state 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 program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . undbx-undbx-0.21/INSTALL000066400000000000000000000224501224265327600147370ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. 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. 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. 4. Type `make install' to install the programs and any data files and documentation. 5. 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. 6. Often, you can also type `make uninstall' to remove the installed files again. 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 `..'. 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. 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'. 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. 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'. Optional Features ================= 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. 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 the options to `configure', and exit. `--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. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. undbx-undbx-0.21/Makefile.am000066400000000000000000000004231224265327600157360ustar00rootroot00000000000000AM_CFLAGS = -Wall -Werror bin_PROGRAMS = undbx undbx_SOURCES = undbx.c dbxsys.c dbxread.c dbxprogress.c emlread.c noinst_HEADERS = dbxsys.h dbxread.h dbxprogress.h emlread.h dist_noinst_SCRIPTS = dist-win32.sh undbx.hta bin_SCRIPTS = undbx.hta dist_noinst_DATA = README.rst undbx-undbx-0.21/README.rst000066400000000000000000000146421224265327600154010ustar00rootroot00000000000000===== UnDBX ===== `UnDBX`_ - Tool to extract, recover and undelete e-mail messages from Outlook Express ``.dbx`` files. .. _UnDBX: http://code.google.com/p/undbx/ Copyright (C) 2008-2013 Avi Rozen DOWNLOAD -------- Windows binary and source code archives are available at ``_ together with corresponding ``sha1sum`` digests, which you can use to verify each archive's integrity. INSTALLATION ------------ There's no installer or setup program. Simply extract the distribution ``.zip`` file to some folder. You should end up with several files/icons in that folder: - the **UnDBX** executable ``undbx.exe`` - the **UnDBX** HTML application ``undbx.hta``, which serves as its graphical user interface - this ``README`` in HTML format - the GPL v3 license (``COPYING``) USAGE ----- Just double-click either of the ``undbx`` icons that you've extracted from the distribution ``.zip`` file. A simple dialog box should appear. If you hit the *Extract!* button in the dialog box, **UnDBX** will extract e-mail messages (as individual ``.eml`` files), from all of the ``.dbx`` files in the Outlook Express storage folder, to corresponding sub-folders on the Desktop. The same dialog box also lets you browse and select other input and output folders, and optionally enable recovery mode for corrupted ``.dbx`` files. OPERATION --------- When run for the first time, **UnDBX** extracts all the messages as individual ``.eml`` files. In subsequent runs **UnDBX** *synchronizes* the output folder with the contents of the ``.dbx`` file: - new messages in the ``.dbx`` file, that do not correspond to existing ``.eml`` files, will be extracted - existing ``.eml`` files, that do not correspond to messages in the ``.dbx`` file, will be treated as deleted messages and will be deleted This way **UnDBX** can facilitate *fast* incremental backup of ``.dbx`` files. The file names of extracted ``.eml`` files are composed from the contents of the ``From:``, ``To:`` and ``Subject:`` message headers. The modification time of each file is set to match the date specified by the ``Date:`` header. In recovery mode, **UnDBX** can open corrupted ``.dbx`` files (including files larger than 2GB) and recover their contents and undelete deleted messages. ADVANCED USAGE --------------- NORMAL OPERATION ~~~~~~~~~~~~~~~~ Run the following command in a command-line window, to extract e-mail messages from all the ``.dbx`` files in ```` to corresponding sub-folders in ````: :: undbx You may also specify a single ``.dbx`` file to extract, instead of a folder. If the destination folder is omitted, the ``.dbx`` files will be extracted to sub-folders in the current working folder. RECOVERY MODE ~~~~~~~~~~~~~ In recovery mode, **UnDBX** attempts to recover e-mail messages from corrupted ``.dbx`` files: :: undbx --recover Again, you may omit the output folder, and you may specify a single ``.dbx`` file, instead of an input folder. During the recovery process **UnDBX** scans the ``.dbx`` file for e-mail message fragments, and collects them into ``.eml`` files. Recovery can take a long while to complete, so please be patient. In recovery mode **UnDBX** always extracts all the messages it can find, instead of extracting only those messages that have not been extracted yet. Keep in mind that recovered messages may be corrupted. DELETED MESSAGES ~~~~~~~~~~~~~~~~ Deleted messages are normally stored by Outlook Express in a special folder (e.g. "Deleted Items"), and can thus be restored by extracting them from the corresponding ``.dbx`` file. Most of the contents of deleted messages still exists in the original ``.dbx`` file, as long it has not been compacted or otherwise modified. In recovery mode, **UnDBX** attempts to undelete any deleted message fragment it can find. NOTE: Outlook Express overwrites the first 4 bytes of every 512-byte chunk of each deleted message. In other words, some data is permanently lost when a message is deleted and *there's no general way to fully recover deleted messages*. SOURCE CODE ----------- SNAPSHOT ~~~~~~~~ **UnDBX** current source code snapshot is available at ``_ REPOSITORY ~~~~~~~~~~ **UnDBX** development source code may be cloned from its public Git repository at ``_ COMPILING ~~~~~~~~~ **UnDBX** uses GNU Autoconf/Automake: :: tar -xvzf undbx-0.20.tar.gz cd undbx-0.20 ./configure make make install On Windows, this means that you need to install either `Cygwin`_ or `MinGW`_. If you got the source code from the source repository, you'll need to generate the ``configure`` script before building **UnDBX**, by running :: autoreconf -vfi .. _Cygwin: http://www.cygwin.com .. _MinGW: http://www.mingw.org BUGS ---- Please report problems via the **UnDBX** issue tracking system: ``_ CERTIFICATION ------------- Well, it works on my machine :-) `[1]`_ `[2]`_ .. _[1]: http://jcooney.net/archive/2007/02/01/42999.aspx .. _[2]: http://www.codinghorror.com/blog/archives/000818.html CREDITS ------- The **UnDBX** .dbx file format parsing code is based on `DbxConv`_ - a DBX to MBOX Converter, Copyright (C) 2008, 2009 Ulrich Krebs **UnDBX** contains `RFC-2822`_, and `RFC-2047`_ parsing code that was adapted from `GNU Mailutils`_ - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. .. _DbxConv: http://www.ukrebs-software.de/english/dbxconv/dbxconv.html .. _RFC-2822: http://www.faqs.org/rfcs/rfc2822 .. _RFC-2047: http://www.faqs.org/rfcs/rfc2047 .. _GNU Mailutils: http://www.gnu.org/software/mailutils/ LICENSE ------- **UnDBX** is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see ``_. undbx-undbx-0.21/UnDBX.xml000066400000000000000000000112451224265327600153500ustar00rootroot00000000000000 3.01 GNU Emacs 23.4.1 Machine Cycle Jerusalem Israel http://machine-cycle.blogspot.com Avi Rozen zungbang+undbx@gmail.com Avi Rozen zungbang+undbx@gmail.com zungbang+undbx@gmail.com zungbang+undbx@gmail.com zungbang+undbx@gmail.com UnDBX 0.21 11 19 2013 Freeware Beta No Install Support WinXP English Communications::Other E-Mail Tools 44607 43.6 0.04 N Days DBX, EML, E-Mail, Outlook Express, extract, convert, recover, undelete, tool, freeware, free, GPL Outlook Express .dbx message extraction tool Tool to extract and recover e-mail messages from Outlook Express .dbx files. Tool to extract, recover and undelete e-mail messages from Outlook Express .dbx files. Tool to extract, recover and undelete e-mail messages from Outlook Express .dbx files. On first run all messages are extracted as individual .eml files. Subsequent runs only update the output directory with new messages, and delete old .eml files that correspond to deleted messages in the .dbx file. Corrupted .dbx files can be opened in recovery mode. Tool to extract, recover and undelete e-mail messages from Outlook Express .dbx files. On first run all messages are extracted as individual .eml files. Subsequent runs only update the output directory with new messages, and delete old .eml files that correspond to deleted messages in the .dbx file. Corrupted .dbx files (including files larger than 2GB) can be opened in recovery mode, in order to recover messages and partially undelete deleted messages. The success of recovery depends on the type and level of .dbx file corruption. http://code.google.com/p/undbx/ http://support.microsoft.com/library/images/support/en-us/HPlogo_OutlookExpress.gif http://support.microsoft.com/library/images/support/en-us/HPlogo_OutlookExpress.gif http://zungbang.googlepages.com/UnDBX.xml http://undbx.googlecode.com/files/undbx-0.21.zip GPLv3 http://www.gnu.org/licenses/ GPLv3 http://www.gnu.org/licenses N undbx-undbx-0.21/configure.ac000066400000000000000000000015661224265327600162010ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) AC_INIT([undbx], [0.21], [avi.rozen@gmail.com]) AC_CANONICAL_SYSTEM AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_CONFIG_SRCDIR([undbx.c]) AC_CONFIG_HEADER([config.h]) # Checks for programs. AC_PROG_CC AC_PROG_INSTALL AC_PROG_MAKE_SET # Checks for libraries. # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([stdlib.h string.h unistd.h utime.h getopt.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T AC_C_BIGENDIAN AC_STRUCT_TIMEZONE # large file support AC_SYS_LARGEFILE # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([getcwd isascii memset mkdir strcasecmp strchr strdup strncasecmp strspn strtoul utime]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT undbx-undbx-0.21/dbxprogress.c000066400000000000000000000142361224265327600164170ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "dbxprogress.h" typedef struct dbx_progress_bar_s { int enabled; int verbose; float max; float last; float delta; } dbx_progress_bar_t; typedef struct dbx_progress_s { dbx_verbosity_t verbosity; dbx_progress_bar_t *bars; int count; } dbx_progress_t; static const char *_dbx_status_label[DBX_STATUS_LAST + 1] = { "OK", "DELETED", "MOVED", "WARNING", "ERROR", "???" }; static void _dbx_progress_vprintf(dbx_status_t status, char *prefix, char *format, va_list ap, char *suffix) { FILE *stream = (status < DBX_STATUS_WARNING)? stdout:stderr; fputs(prefix, stream); if (format) vfprintf(stream, format, ap); fputs(suffix, stream); fflush(stream); } static void _dbx_progress_printf(dbx_status_t status, char *format, ...) { va_list ap; va_start(ap, format); _dbx_progress_vprintf(status, "", format, ap, ""); va_end(ap); } static const char *_dbx_status_string(dbx_status_t status) { if (status < DBX_STATUS_OK || status >= DBX_STATUS_LAST) status = DBX_STATUS_LAST; return _dbx_status_label[status]; } static void _dbx_progress_update(dbx_status_t status, dbx_progress_bar_t *bar, unsigned int n, char *format, va_list ap) { if (format == NULL || !bar->verbose) { if (n + 1 != 0) { if ((n + 1) < bar->max && n - bar->last < bar->delta) return; bar->last = n; _dbx_progress_printf(DBX_STATUS_OK, "\b\b\b\b\b\b%5.1f%%", (n + 1) / bar->max * 100.0); fflush(stdout); } } else { if (n + 1 != 0) _dbx_progress_printf(DBX_STATUS_OK, "\n%5.1f%% ", (n + 1) / bar->max * 100.0); else _dbx_progress_printf(DBX_STATUS_OK, "\n "); _dbx_progress_printf(DBX_STATUS_OK, "[%-7s] ", _dbx_status_string(status)); _dbx_progress_vprintf(DBX_STATUS_OK, "", format, ap, ""); } } dbx_progress_handle_t dbx_progress_new(dbx_verbosity_t level) { dbx_progress_handle_t handle = (dbx_progress_handle_t) calloc(1, sizeof(dbx_progress_t)); if (handle) handle->verbosity = level; else perror("dbx_progress_new (calloc)"); return handle; } void dbx_progress_delete(dbx_progress_handle_t handle) { if (handle) free(handle); } void dbx_progress_push(dbx_progress_handle_t handle, dbx_verbosity_t level, unsigned int n, char *format, ...) { dbx_progress_bar_t *bar = NULL; dbx_progress_bar_t *bars = NULL; if (handle == NULL) return; bars = (dbx_progress_bar_t *)realloc(handle->bars, (handle->count + 1) * sizeof(dbx_progress_bar_t)); if (bars == NULL) { perror("dbx_progress_push (realloc)"); return; } handle->bars = bars; bar = handle->bars + handle->count; handle->count++; bar->enabled = (level <= handle->verbosity); bar->verbose = (level < handle->verbosity); bar->last = 0; bar->max = (float) n; bar->delta = bar->max / 1000.0; if (bar->enabled) { va_list ap; va_start(ap, format); _dbx_progress_vprintf(DBX_STATUS_OK, "", format, ap, ": "); va_end(ap); } } void dbx_progress_pop(dbx_progress_handle_t handle, char *format, ...) { dbx_progress_bar_t *bar = handle->bars + handle->count - 1; dbx_progress_bar_t *bars = NULL; if (handle == NULL || handle->count == 0) return; if (bar->enabled) { va_list ap; va_start(ap, format); _dbx_progress_vprintf(DBX_STATUS_OK, "\n", format, ap, format? "\n":""); va_end(ap); } if (handle->count == 1) { free(handle->bars); } else { bars = (dbx_progress_bar_t *)realloc(handle->bars, (handle->count - 1) * sizeof(dbx_progress_bar_t)); if (bars == NULL) { perror("dbx_progress_pop (realloc)"); return; } } handle->bars = bars; handle->count--; } void dbx_progress_update(dbx_progress_handle_t handle, dbx_status_t status, unsigned int n, char *format, ...) { dbx_progress_bar_t *bar = NULL; if (handle == NULL || handle->count == 0) return; bar = handle->bars + handle->count - 1; if (bar->enabled) { va_list ap; va_start(ap, format); _dbx_progress_update(status, bar, n, format, ap); va_end(ap); } } void dbx_progress_message(dbx_progress_handle_t handle, dbx_status_t status, char *format, ...) { dbx_progress_bar_t *bar = NULL; if (handle && handle->count > 0) bar = handle->bars + handle->count - 1; if (bar == NULL || bar->enabled) { va_list ap; va_start(ap, format); _dbx_progress_vprintf(status, "", format, ap, "\n"); va_end(ap); } } undbx-undbx-0.21/dbxprogress.h000066400000000000000000000047101224265327600164200ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _DBX_PROGRESS_H_ #define _DBX_PROGRESS_H_ #ifdef __cplusplus extern "C" { #endif typedef enum { DBX_STATUS_OK, DBX_STATUS_DELETED, DBX_STATUS_MOVED, DBX_STATUS_WARNING, DBX_STATUS_ERROR, DBX_STATUS_LAST } dbx_status_t; typedef enum { DBX_VERBOSITY_QUIET, DBX_VERBOSITY_ERROR, DBX_VERBOSITY_WARNING, DBX_VERBOSITY_INFO, DBX_VERBOSITY_VERBOSE, DBX_VERBOSITY_DEBUG, } dbx_verbosity_t; typedef struct dbx_progress_s *dbx_progress_handle_t; dbx_progress_handle_t dbx_progress_new(dbx_verbosity_t level); void dbx_progress_delete(dbx_progress_handle_t handle); void dbx_progress_push(dbx_progress_handle_t handle, dbx_verbosity_t level, unsigned int n, char *format, ...); void dbx_progress_pop(dbx_progress_handle_t handle, char *format, ...); void dbx_progress_update(dbx_progress_handle_t handle, dbx_status_t status, unsigned int n, char *format, ...); void dbx_progress_message(dbx_progress_handle_t handle, dbx_status_t status, char *format, ...); #ifdef __cplusplus }; #endif #endif /* _DBX_PROGRESS_H_ */ undbx-undbx-0.21/dbxread.c000066400000000000000000000642731224265327600154740ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include "dbxread.h" #include "emlread.h" #define INDEX_POINTER 0xE4 #define ITEM_COUNT 0xC4 static int _dbx_info_cmp(const dbx_info_t *ia, const dbx_info_t *ib) { int res = strcmp(ia->filename, ib->filename); if (res == 0) { res = ia->index - ib->index; } return res; } static char *_dbx_read_string(FILE *file, int offset) { char c[256]; char *s = NULL; int n = 0; int l = 0; fseek(file, offset, SEEK_SET); c[255]='\0'; do { sys_fread(c, 1, 255, file); l = strlen(c); s = realloc(s, n + l + 1); strncpy(s + n, c, l); n += l; s[n] = '\0'; } while (l == 255); return s; } static filetime_t _dbx_read_date(FILE *file, int offset) { filetime_t filetime = 0; fseek(file, offset, SEEK_SET); sys_fread_long_long((long long int *)&filetime, file); return filetime; } static int _dbx_read_int(FILE *file, int offset, int value) { int val = value; if (offset) { fseek(file, offset, SEEK_SET); sys_fread_int(&val, file); } return val; } static int _dbx_read_msg_offset(dbx_t *dbx, int msg_number) { int size = 0; int index = 0; int value = 0; unsigned char type = 0; int msg_offset = 0; int msg_offset_ptr = 0; char count = 0; int i = 0; index = dbx->info[msg_number].index; fseek(dbx->file, index + 4, SEEK_SET); sys_fread_int(&size, dbx->file); fseek(dbx->file, 2, SEEK_CUR); sys_fread(&count, 1, 1, dbx->file); fseek(dbx->file, 1, SEEK_CUR); for (i = 0; i < count; i++) { sys_fread_int((int *)&value, dbx->file); type = value & 0xFF; value = (value >> 8) & 0xFFFFFF; if (type == 0x84) { msg_offset = value; break; } if (type == 0x04) { msg_offset_ptr = index + 12 + value + 4 * count; break; } } if (msg_offset == 0 && msg_offset_ptr != 0) { fseek(dbx->file, msg_offset_ptr, SEEK_SET); sys_fread_int(&msg_offset, dbx->file); } return msg_offset; } static void _dbx_sanitize_filename(char *filename) { char *c = NULL; static const char * const invalid_characters = "\\/?\"<>*|:"; static const char valid_char = '_'; if (!filename) return; for (c = filename; *c; c++) if ((unsigned char)*c < 32 || strchr(invalid_characters, *c)) *c = valid_char; } static void _dbx_set_filename(dbx_info_t *info) { char filename[DBX_MAX_FILENAME]; char suffix[sizeof(".00000000.00000000.eml.00000000")]; snprintf(filename, DBX_MAX_FILENAME - sizeof(suffix), "%.15s_%.15s_%.15s_%.15s_%s", info->sender_name? info->sender_name:"_(no_name)_", info->sender_address? info->sender_address:"_(no_address)_", info->receiver_name? info->receiver_name:"_(no_name)_", info->receiver_address? info->receiver_address:"_(no_address)_", info->subject? info->subject:"(no_subject)"); sprintf(suffix, ".%08X.%08X.eml.00000000", (unsigned int) (info->receive_create_time & 0xFFFFFFFFULL), (unsigned int) (info->send_create_time & 0xFFFFFFFFULL)); strcat(filename, suffix); _dbx_sanitize_filename(filename); info->filename = strdup(filename); /* remove trailing extra space (reserved for uniquification of filename) */ info->filename[strlen(info->filename) - sizeof("00000000")] = '\0'; } static void _dbx_uniquify_filenames(dbx_t *dbx) { int i = 1; static const int cl = sizeof(".eml") - 1; while (i < dbx->message_count) { int n; /* skip info entries with non-equal filenames */ while (i < dbx->message_count && strcmp(dbx->info[i - 1].filename, dbx->info[i].filename) != 0) i++; /* uniquify equal filename entries */ n = 1; if (i < dbx->message_count) { do { sprintf(dbx->info[i - 1].filename + strlen(dbx->info[i - 1].filename) - cl, ".%08X.eml", (unsigned int) dbx->info[i - 1].index); i++; n++; } while (i < dbx->message_count && strcmp(dbx->info[i - 1].filename, dbx->info[i].filename) == 0); sprintf(dbx->info[i - 1].filename + strlen(dbx->info[i - 1].filename) - cl, ".%08X.eml", (unsigned int) dbx->info[i - 1].index); } } } static void _dbx_read_info(dbx_t *dbx) { int i; for(i = 0; i < dbx->message_count; i++) { int j; int size; int count = 0; int index = dbx->info[i].index; int offset = 0; int pos = index + 12; fseek(dbx->file, index + 4, SEEK_SET); sys_fread_int(&size, dbx->file); sys_fread_int(&count, dbx->file); count = (count & 0x00FF0000) >> 16; dbx->info[i].valid = 0; for (j = 0; j < count; j++) { int type = 0; unsigned int value = 0; fseek(dbx->file, pos, SEEK_SET); sys_fread_int((int*)&value, dbx->file); type = value & 0xFF; value = (value >> 8) & 0xFFFFFF; /* msb means direct storage */ offset = (type & 0x80)? 0:(index + 12 + 4 * count + value); /* dirt ugly code follows ... */ switch (type & 0x7f) { case 0x00: dbx->info[i].message_index = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_INDEX; break; case 0x01: dbx->info[i].flags = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_FLAGS; break; case 0x02: dbx->info[i].send_create_time = _dbx_read_date(dbx->file, offset); break; case 0x03: dbx->info[i].body_lines = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_BODYLINES; break; case 0x04: dbx->info[i].message_address = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_MSGADDR; break; case 0x05: dbx->info[i].original_subject = _dbx_read_string(dbx->file, offset); break; case 0x06: dbx->info[i].save_time = _dbx_read_date(dbx->file, offset); break; case 0x07: dbx->info[i].message_id = _dbx_read_string(dbx->file, offset); break; case 0x08: dbx->info[i].subject = _dbx_read_string(dbx->file, offset); break; case 0x09: dbx->info[i].sender_address_and_name = _dbx_read_string(dbx->file, offset); break; case 0x0A: dbx->info[i].message_id_replied_to = _dbx_read_string(dbx->file, offset); break; case 0x0B: dbx->info[i].server_newsgroup_message_number = _dbx_read_string(dbx->file, offset); break; case 0x0C: dbx->info[i].server = _dbx_read_string(dbx->file, offset); break; case 0x0D: dbx->info[i].sender_name = _dbx_read_string(dbx->file, offset); break; case 0x0E: dbx->info[i].sender_address = _dbx_read_string(dbx->file, offset); break; case 0x10: dbx->info[i].message_priority = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_MSGPRIO; break; case 0x11: dbx->info[i].message_size = _dbx_read_int(dbx->file, offset, value); dbx->info[i].valid |= DBX_MASK_MSGSIZE; break; case 0x12: dbx->info[i].receive_create_time = _dbx_read_date(dbx->file, offset); break; case 0x13: dbx->info[i].receiver_name = _dbx_read_string(dbx->file, offset); break; case 0x14: dbx->info[i].receiver_address = _dbx_read_string(dbx->file, offset); break; case 0x1A: dbx->info[i].account_name = _dbx_read_string(dbx->file, offset); break; case 0x1B: dbx->info[i].account_registry_key = _dbx_read_string(dbx->file, offset); break; } pos += 4; } dbx->info[i].offset = _dbx_read_msg_offset(dbx, i); if (dbx->options->safe_mode) { char filename[DBX_MAX_FILENAME]; int msg_offset = dbx->info[i].offset; if (dbx->info[i].offset == 0) /* message only in index, not downloaded yet */ msg_offset = dbx->info[i].index; sprintf(filename, "%08X.eml", (unsigned int) msg_offset); dbx->info[i].filename = strdup(filename); } else { _dbx_set_filename(dbx->info + i); } } } static int _dbx_read_index(dbx_t *dbx, int pos) { int i; int next_table; char ptr_count = 0; int index_count; if (pos <= 0 || dbx->file_size <= (unsigned long long int)pos) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING, "DBX file %s is corrupted (bad seek offset %08X)", dbx->filename, pos); return 0; } fseek(dbx->file, pos + 8, SEEK_SET); sys_fread_int(&next_table, dbx->file); fseek(dbx->file, 5, SEEK_CUR); sys_fread(&ptr_count, 1, 1, dbx->file); if (ptr_count <= 0) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING, "DBX file %s is corrupted (bad count %d at offset %08X)", dbx->filename, ptr_count, pos + 8 + 4 + 5); return 0; } fseek(dbx->file, 2, SEEK_CUR); sys_fread_int(&index_count, dbx->file); if (index_count > 0) { if (!_dbx_read_index(dbx, next_table)) return 0; } pos += 24; dbx->info = (dbx_info_t *)realloc(dbx->info, (dbx->capacity + ptr_count) * sizeof(dbx_info_t)); dbx->capacity += ptr_count; for (i = 0; i < ptr_count; i++) { int index_ptr; fseek(dbx->file, pos, SEEK_SET); sys_fread_int(&index_ptr, dbx->file); sys_fread_int(&next_table, dbx->file); sys_fread_int(&index_count, dbx->file); memset(dbx->info + dbx->message_count, 0, sizeof(dbx_info_t)); dbx->info[dbx->message_count].index = index_ptr; dbx->message_count++; pos += 12; if (index_count > 0) { if (!_dbx_read_index(dbx, next_table)) return 0; } } return 1; } static int _dbx_read_indexes(dbx_t *dbx) { int index_ptr; int item_count; fseek(dbx->file, INDEX_POINTER, SEEK_SET); sys_fread_int(&index_ptr, dbx->file); fseek(dbx->file, ITEM_COUNT, SEEK_SET); sys_fread_int(&item_count, dbx->file); if (item_count > 0) return _dbx_read_index(dbx, index_ptr); else return 0; } static dbx_chains_t *_dbx_get_scan_chains(dbx_t *dbx, long long int offset, int deleted) { int i = 0; dbx_chains_t *scan = NULL; for (i = 0; i < dbx->scan_count; i++) { if (dbx->scan[i].offset == offset && dbx->scan[i].deleted == deleted) { return dbx->scan + i; } } dbx->scan_count++; dbx->scan = (dbx_chains_t *)realloc(dbx->scan, sizeof(dbx_chains_t) * dbx->scan_count); scan = dbx->scan + dbx->scan_count - 1; scan->offset = offset; scan->deleted = deleted; scan->fragment_count = 0; scan->fragments = NULL; scan->count = 0; scan->chains = NULL; return scan; } static void _dbx_scan(dbx_t *dbx) { int header[8] = {0}; int header_start = 0; int ready = 0; unsigned long long int i = 0; int j = 0; dbx_progress_push(dbx->progress_handle, DBX_VERBOSITY_INFO, dbx->file_size, "Scanning %s", dbx->filename); for (i = 0; i < dbx->file_size; i += 4) { int deleted = 0; dbx_chains_t *chains = NULL; dbx_fragment_t *other = NULL; dbx_fragment_t *fragment = NULL; dbx_progress_update(dbx->progress_handle, DBX_STATUS_OK, i, NULL); /* initialize header buffer */ if (!ready) { header_start = 0; for (j = 0; j < 4; j++) sys_fread_int(header + j, dbx->file); i += 16; ready = 1; } sys_fread_int(header + ((header_start + 4) & 7), dbx->file); /* message fragment header signature: ================================= 1st word value equals offset into file 2nd word is 0x200 3rd word is fragment length: must be positive, but not more than 0x200 4th word value is the file offset of the next fragment, or 0 if last deleted message fragment header signature: ========================================= 1st word value equals offset into file 2nd word is 0x1FC 3rd word is 0x210 4th word value is offset of next fragment or 0 if last 5th word value is offset of previous fragment (clobbering message data!) sanity: we check that all offsets are less than file size, and are a multiple of 4 and that fragment does not point to itself */ int header_offset_diff = header[header_start] - i; int message_fragment_found = (header[(header_start + 1) & 7] == 0x200 && header[(header_start + 2) & 7] > 0 && header[(header_start + 2) & 7] <= 0x200 && header[(header_start + 3) & 7] >= 0 && header[(header_start + 3) & 7] < dbx->file_size && (header[(header_start + 3) & 7] & 3) == 0 && header[(header_start + 3) & 7] != header[header_start])? 1:0; int deleted_fragment_found = (header[(header_start + 1) & 7] == 0x1FC && header[(header_start + 2) & 7] == 0x210 && header[(header_start + 3) & 7] < dbx->file_size && (header[(header_start + 3) & 7] & 3) == 0 && header[(header_start + 3) & 7] != header[header_start] && header[(header_start + 4) & 7] >= 0 && header[(header_start + 4) & 7] < dbx->file_size && (header[(header_start + 4) & 7] & 3) == 0)? 1:0; if (!message_fragment_found && !deleted_fragment_found) { header_start = (header_start + 1) & 7; continue; } if (dbx->options->debug) { int iii; for (iii = 0; iii < 5; iii++) { printf("%08X ", header[(header_start + iii) & 7]); } printf("\n"); } /* add fragment to fragment list */ deleted = (header[(header_start + 1) & 7] == 0x1FC)? 1:0; chains = _dbx_get_scan_chains(dbx, header_offset_diff, deleted); if ((chains->fragment_count % 4096) == 0) chains->fragments = (dbx_fragment_t *)realloc(chains->fragments, sizeof(dbx_fragment_t) * (chains->fragment_count + 4096)); fragment = chains->fragments + chains->fragment_count; fragment->prev = -1; fragment->next = -1; fragment->offset = header[header_start]; fragment->offset_next = header[(header_start + 3) & 7]; fragment->offset_prev = header[(header_start + 4) & 7]; /* only valid for deleted messages */ fragment->size = header[(header_start + 2) & 7]; chains->fragment_count++; chains->count++; /* check if previous fragment is next fragment, if we already passed it */ other = fragment - 1; if (other >= chains->fragments) { if (fragment->offset_next && fragment->offset_next < fragment->offset && other->prev < 0 && /* avoid already used fragments */ fragment->offset_next == other->offset && (!deleted || other->offset_prev == fragment->offset)) { fragment->next = other - chains->fragments; other->prev = chains->fragment_count - 1; chains->count--; } else if (other->next < 0 && fragment->offset == other->offset_next && (!deleted || fragment->offset_prev == other->offset)) { fragment->prev = other - chains->fragments; other->next = chains->fragment_count - 1; chains->count--; } } /* skip contents of fragment */ i += 0x200 - 4; fseek(dbx->file, i + 20, SEEK_SET); /* header buffer should be refilled */ ready = 0; } for (j = 0; j < dbx->scan_count; j++) { if (dbx->scan[j].count) { dbx_chains_t *chains = NULL; dbx_fragment_t *other = NULL; dbx_fragment_t *fragment = NULL; unsigned int k0, k1, k2; chains = &dbx->scan[j]; for (i = 0; i < chains->fragment_count; i++) { fragment = chains->fragments + i; if (fragment->offset_next == 0 || fragment->next >= 0) continue; k0 = 0; k2 = chains->fragment_count; for (k1 = i + (i < k2)? 1:0; k0 < k2; k1 = (k0 + k2) / 2) { other = chains->fragments + k1; if (other->offset < fragment->offset_next) { if (k1 == k0) break; k0 = k1; continue; } if (other->offset > fragment->offset_next) { k2 = k1; continue; } if (other->prev >= 0) break; if (dbx->scan[j].deleted && other->offset_prev != fragment->offset) break; fragment->next = k1; other->prev = i; chains->count--; break; } } } } /* collect the fragments that start messages chains messages start with fragments where prev == -1, i.e. no other fragment points to it */ for (j = 0; j < dbx->scan_count; j++) { if (dbx->scan[j].count) { int nm = 0; int nf = 0; int cnf = 0; dbx_fragment_t *pf = NULL; dbx->scan[j].chains = (dbx_fragment_t **)calloc(dbx->scan[j].count, sizeof(dbx_fragment_t *)); dbx->scan[j].chain_fragment_count = (int *)calloc(dbx->scan[j].count, sizeof(int)); for (nm = 0; nm < dbx->scan[j].count; nm++) { while (dbx->scan[j].fragments[nf].prev >= 0) nf++; dbx->scan[j].chains[nm] = dbx->scan[j].fragments + nf; /* count fragments in chain */ for (cnf = nf, pf = dbx->scan[j].chains[nm]; cnf >= 0; cnf = pf->next) { dbx->scan[j].chain_fragment_count[nm]++; pf = dbx->scan[j].fragments + cnf; } nf++; } } } dbx_progress_update(dbx->progress_handle, DBX_STATUS_OK, dbx->file_size, NULL); dbx_progress_pop(dbx->progress_handle, NULL); } static void _dbx_init(dbx_t *dbx) { int i = 0; unsigned int signature[4]; dbx->message_count = 0; dbx->capacity = 0; dbx->info = NULL; for(i = 0; i < 4; i++) sys_fread_int((int *)(signature + i), dbx->file); if (signature[0] == 0xFE12ADCF && signature[1] == 0x6F74FDC5 && signature[2] == 0x11D1E366 && signature[3] == 0xC0004E9A) { dbx->type = DBX_TYPE_EMAIL; } else if (signature[0] == 0x36464D4A && signature[1] == 0x00010003) { dbx->type = DBX_TYPE_OE4; } else if (signature[0]==0xFE12ADCF && signature[1]==0x6F74FDC6 && signature[2]==0x11D1E366 && signature[3]==0xC0004E9A) { dbx->type = DBX_TYPE_FOLDER; } else { dbx->type = DBX_TYPE_UNKNOWN; } if (dbx->options->recover) { /* we ignore file type in recovery mode */ _dbx_scan(dbx); } else if (dbx->type == DBX_TYPE_EMAIL) { _dbx_read_indexes(dbx); _dbx_read_info(dbx); qsort(dbx->info, dbx->message_count, sizeof(dbx_info_t), (dbx_cmpfunc_t) _dbx_info_cmp); if (!dbx->options->safe_mode) /* filenames should already be unique in safe mode */ _dbx_uniquify_filenames(dbx); } } dbx_t *dbx_open(char *filename, dbx_options_t *options) { dbx_t *dbx = (dbx_t *) calloc(1, sizeof(dbx_t)); if (dbx) { dbx->progress_handle = dbx_progress_new(options->verbosity); dbx->file = fopen(filename, "rb"); if (dbx->file == NULL) { free(dbx); dbx = NULL; } else { struct stat st; if (stat(filename, &st) != 0) { perror("dbx_open"); dbx = NULL; } else { dbx->filename = strdup(filename); dbx->file_size = sys_filesize(".", filename); dbx->options = options; _dbx_init(dbx); } } } return dbx; } void dbx_close(dbx_t *dbx) { int i; if (dbx) { if (dbx->file) { fclose(dbx->file); dbx->file = NULL; } for(i = 0; i < dbx->message_count; i++) { free(dbx->info[i].filename); free(dbx->info[i].original_subject); free(dbx->info[i].message_id); free(dbx->info[i].subject); free(dbx->info[i].sender_address_and_name); free(dbx->info[i].message_id_replied_to); free(dbx->info[i].server_newsgroup_message_number); free(dbx->info[i].server); free(dbx->info[i].sender_name); free(dbx->info[i].sender_address); free(dbx->info[i].receiver_name); free(dbx->info[i].receiver_address); free(dbx->info[i].account_name); free(dbx->info[i].account_registry_key); } free(dbx->info); dbx->info = NULL; free(dbx->filename); for (i = 0; i < dbx->scan_count; i++) { if (dbx->scan[i].chains) { free(dbx->scan[i].chains); dbx->scan[i].chains = NULL; dbx->scan[i].count = 0; } if (dbx->scan[i].chain_fragment_count) { free(dbx->scan[i].chain_fragment_count); dbx->scan[i].chain_fragment_count = NULL; } if (dbx->scan[i].fragments) { free(dbx->scan[i].fragments); dbx->scan[i].fragments = NULL; dbx->scan[i].fragment_count = 0; } } if (dbx->scan) { free(dbx->scan); dbx->scan = NULL; dbx->scan_count = 0; } dbx_progress_delete(dbx->progress_handle); free(dbx); } } char *dbx_message(dbx_t *dbx, int msg_number, unsigned int *psize) { unsigned int total_size = 0; short block_size = 0; int i = 0; char *buf = NULL; if (psize) *psize = 0; if (dbx == NULL || msg_number >= dbx->message_count) return NULL; i = dbx->info[msg_number].offset; total_size = 0; while (i != 0) { fseek(dbx->file, i + 8, SEEK_SET); block_size=0; sys_fread_short(&block_size, dbx->file); if (block_size <= 0 || block_size > 0x200) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING, "DBX file %s is corrupted (bad block size %04X at offset %08X)", dbx->filename, block_size, i + 8); break; } fseek(dbx->file, 2, SEEK_CUR); sys_fread_int(&i, dbx->file); total_size += block_size; buf = realloc(buf, total_size + 1); sys_fread(buf + total_size - block_size, block_size, 1, dbx->file); } if (buf) buf[total_size]='\0'; if (psize) *psize = total_size; return buf; } char *dbx_recover_message(dbx_t *dbx, int chain_index, int msg_number, unsigned int *psize, time_t *ptimestamp, char **pfilename) { unsigned int size = 0; char filename[DBX_MAX_FILENAME]; char suffix[sizeof(".0000000000000000.eml")]; char *message = NULL; dbx_fragment_t *pfragment = NULL; int ifragment = dbx->scan[chain_index].chains[msg_number] - dbx->scan[chain_index].fragments; unsigned int fsize = 0; time_t timestamp = 0; char *subject = NULL; char *to = NULL; char *from = NULL; if (dbx->scan[chain_index].chain_fragment_count[msg_number] > 0) message = (char *)calloc(1, dbx->scan[chain_index].chain_fragment_count[msg_number] * 0x200 + 1); if (message == NULL) return message; for ( ; ifragment >= 0; ifragment = pfragment->next) { pfragment = dbx->scan[chain_index].fragments + ifragment; /* deleted fragments have size 0x210, which is wrong - it's 0x200 */ fsize = pfragment->size <= 0x200? pfragment->size : 0x200; fseek(dbx->file, pfragment->offset + 16 - dbx->scan[chain_index].offset, SEEK_SET); sys_fread(message + size, fsize, 1, dbx->file); /* each deleted fragment starts with bad 4 bytes (it's set to the offset of the previous fragment) so we replace them with 4 dashes, which eases eml parsing and should at least make the text readable */ if (dbx->scan[chain_index].deleted) memset(message + size, '-', 4); if (dbx->options->debug) printf("%08X: %08X %08X %04X\n", size, pfragment->offset, pfragment->offset_next, fsize); size += fsize; } if (message) { message[size] = '\0'; /* lose trailing nul characters in deleted messages, since size of last fragment is unknown */ if (dbx->scan[chain_index].deleted) { int zeros = 0; while (zeros <= size && message[size - zeros] == 0) zeros++; size -= zeros - 1; } eml_parse(message, &subject, &from, &to, ×tamp); } unsigned long long int message_offset = dbx->scan[chain_index].chains[msg_number]->offset - dbx->scan[chain_index].offset; if (dbx->options->safe_mode) { sprintf(filename, "%016" #ifndef WIN32 "ll" #else "I64" #endif "X.eml", message_offset); } else { snprintf(filename, DBX_MAX_FILENAME - sizeof(suffix), "%.31s_%.31s_%s", from? (from[0]=='"'? from+1:from):"_(no_sender)", to? (to[0]=='"'? to+1:to):"(no_receiver)", subject? subject:"(no_subject)"); sprintf(suffix, ".%016" #ifndef WIN32 "ll" #else "I64" #endif "X.eml", message_offset); strcat(filename, suffix); _dbx_sanitize_filename(filename); } if (message) { free(subject); free(to); free(from); } *pfilename = strdup(filename); *ptimestamp = timestamp; *psize = size; return message; } undbx-undbx-0.21/dbxread.h000066400000000000000000000072511224265327600154720ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _DBX_READ_H_ #define _DBX_READ_H_ #ifdef __cplusplus extern "C" { #endif #include "dbxsys.h" #include "dbxprogress.h" #define DBX_MAX_FILENAME 128 typedef int (*dbx_cmpfunc_t)(const void *, const void *); typedef enum { DBX_TYPE_UNKNOWN, DBX_TYPE_EMAIL, DBX_TYPE_OE4, DBX_TYPE_FOLDER } dbx_type_t; typedef enum { DBX_MASK_INDEX = 0x01, DBX_MASK_FLAGS = 0x02, DBX_MASK_BODYLINES = 0x04, DBX_MASK_MSGADDR = 0x08, DBX_MASK_MSGPRIO = 0x10, DBX_MASK_MSGSIZE = 0x20 } dbx_mask_t; typedef struct dbx_fragment_s { unsigned int offset; unsigned int offset_next; unsigned int offset_prev; unsigned int size; int prev; int next; } dbx_fragment_t; typedef struct dbx_chains_s { long long int offset; int deleted; int fragment_count; dbx_fragment_t *fragments; int count; dbx_fragment_t **chains; int *chain_fragment_count; } dbx_chains_t; typedef struct dbx_info_s { int index; int offset; int extract; char *filename; dbx_mask_t valid; unsigned int message_index; unsigned int flags; filetime_t send_create_time; unsigned int body_lines; unsigned int message_address; char *original_subject; filetime_t save_time; char *message_id; char *subject; char *sender_address_and_name; char *message_id_replied_to; char *server_newsgroup_message_number; char *server; char *sender_name; char *sender_address; unsigned int message_priority; unsigned int message_size; filetime_t receive_create_time; char *receiver_name; char *receiver_address; char *account_name; char *account_registry_key; } dbx_info_t; typedef struct { int recover; int safe_mode; int delete_deleted; int ignore0; dbx_verbosity_t verbosity; int debug; } dbx_options_t; typedef struct dbx_s { char *filename; FILE *file; dbx_options_t *options; dbx_progress_handle_t progress_handle; unsigned long long int file_size; dbx_type_t type; int message_count; int capacity; dbx_info_t *info; dbx_chains_t *scan; int scan_count; } dbx_t; dbx_t *dbx_open(char *filename, dbx_options_t *options); void dbx_close(dbx_t *dbx); char *dbx_message(dbx_t *dbx, int msg_number, unsigned int *psize); char *dbx_recover_message(dbx_t *dbx, int chain_index, int msg_number, unsigned int *psize, time_t *ptimestamp, char **pfilename); #ifdef __cplusplus }; #endif #endif /* _DBX_READ_H_ */ undbx-undbx-0.21/dbxsys.c000066400000000000000000000177651224265327600154030ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H # include #else # define WORDS_BIGENDIAN 1 /* safe default here (see sys_fread_* funcs) */ #endif #include #include #include #include #include #include #include "dbxsys.h" #define JAN1ST1970 0x19DB1DED53E8000ULL #define NSPERSEC 1000000000ULL #if defined(__APPLE__) || defined(__unix__) #include #include #include #include static char **_sys_glob(char *pattern, int *num_files) { int i = 0; char **files = NULL; glob_t result; glob(pattern, GLOB_MARK, NULL, &result); files = (char **)calloc(result.gl_pathc + 1, sizeof(char *)); for (i = 0 ; i < result.gl_pathc; i++) { files[i] = strdup(result.gl_pathv[i]); } if (num_files) *num_files = result.gl_pathc; globfree(&result); return files; } static int _sys_mkdir(char *path) { int rc = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); return (rc == 0 || errno == EEXIST)? 0:rc; } static int _sys_chdir(char *dir) { return chdir(dir); } static char *_sys_getcwd(void) { return getcwd(NULL, 0); } static int _sys_set_time(char *filename, time_t timestamp) { struct utimbuf timbuf; timbuf.actime = timestamp; timbuf.modtime = timestamp; return utime(filename, &timbuf); } #endif /* defined(__APPLE__) || defined(__unix__) */ #ifdef _WIN32 #include #include #include static char **_sys_glob(char *pattern, int *num_files) { char **files = NULL; int n = 0; WIN32_FIND_DATA f; HANDLE h = FindFirstFile(pattern, &f); if (h != INVALID_HANDLE_VALUE) { do { files = (char **)realloc(files, sizeof(char *) * (n + 1)); files[n] = strdup(f.cFileName); n++; } while (FindNextFile(h, &f)); files = (char **)realloc(files, sizeof(char *) * (n + 1)); files[n] = NULL; FindClose(h); } if (num_files) *num_files = n; return files; } static int _sys_mkdir(char *path) { int rc = _mkdir(path); return (rc == 0 || errno == EEXIST)? 0:rc; } static int _sys_chdir(char *dir) { int rc; /* _chdir doesn't if dir is just C: - must add \ */ int l = strlen(dir); char *path = strdup(dir); if (path == NULL) return -1; if (path[l-1] == ':') { path = (char *)realloc(path, l + 2); if (path == NULL) return -1; path[l] = '\\'; path[l+1] = '\0'; } rc = _chdir(path); free(path); return rc; } static char *_sys_getcwd(void) { return _getcwd(NULL, 0); } static int _sys_set_time(char *filename, time_t timestamp) { struct _utimbuf timbuf; timbuf.actime = timestamp; timbuf.modtime = timestamp; return _utime(filename, &timbuf); } #endif /* _WIN32 */ char **sys_glob(char *parent, char *pattern, int *num_files) { int rc = 0; char *cwd = NULL; char **files = NULL; *num_files = 0; cwd = sys_getcwd(); if (cwd == NULL) return NULL; rc = sys_chdir(parent); if (rc != 0) { free(cwd); return NULL; } files = _sys_glob(pattern, num_files); sys_chdir(cwd); free(cwd); return files; } void sys_glob_free(char **files) { if (files) { int i; for(i = 0; files[i]; i++) { free(files[i]); files[i] = NULL; } free(files); } } int sys_mkdir(char *parent, char *dir) { int rc = 0; char *cwd = NULL; rc = _sys_mkdir(parent); if (rc != 0) return rc; cwd = sys_getcwd(); if (cwd == NULL) return -1; rc = sys_chdir(parent); if (rc != 0) { free(cwd); return -1; } rc = _sys_mkdir(dir); sys_chdir(cwd); free(cwd); return rc; } int sys_chdir(char *dir) { if (dir == NULL) return -1; return _sys_chdir(dir); } char *sys_getcwd(void) { return _sys_getcwd(); } unsigned long long int sys_filesize(char *parent, char *filename) { int rc = 0; unsigned long long int size = 0; char *cwd = NULL; struct stat buf; cwd = sys_getcwd(); if (cwd == NULL) return -1; rc = sys_chdir(parent); if (rc != 0) { free(cwd); return -1; } rc = stat(filename, &buf); size = (rc == 0)? buf.st_size:-1; sys_chdir(cwd); free(cwd); return size; } int sys_delete(char *parent, char *filename) { int rc = 0; char *cwd = NULL; cwd = sys_getcwd(); if (cwd == NULL) return -1; rc = sys_chdir(parent); if (rc != 0) { free(cwd); return -1; } rc = unlink(filename); sys_chdir(cwd); free(cwd); return rc; } int sys_move(char *parent, char *filename, char *destination) { int rc = 0; char *cwd = NULL; char *new_filename = NULL; cwd = sys_getcwd(); if (cwd == NULL) return -1; rc = sys_chdir(parent); if (rc != 0) { free(cwd); return -1; } new_filename = (char *)malloc(sizeof(char) * (strlen(destination) + strlen("/") + strlen(filename) + 1)); if (new_filename) { sprintf(new_filename, "%s/%s", destination, filename); rc = rename(filename, new_filename); free(new_filename); } sys_chdir(cwd); free(cwd); return rc; } int sys_set_time(char *filename, time_t timestamp) { return _sys_set_time(filename, timestamp); } int sys_set_filetime(char *filename, filetime_t filetime) { filetime_t t = (filetime - JAN1ST1970) / ((unsigned long long int) (NSPERSEC / 100)); return sys_set_time(filename, (time_t)t); } char *sys_basename(char *path) { return basename(path); } char *sys_dirname(char *path) { return dirname(path); } size_t sys_fread(void *ptr, size_t size, size_t nitems, FILE *stream) { return fread(ptr, size, nitems, stream); } void sys_fread_long_long(long long int *value, FILE *file) { #ifndef WORDS_BIGENDIAN sys_fread(value, 1, sizeof(long long int), file); #else /* the following code is endianness neutral */ long long int llw = 0; llw = (long long int) (fgetc(file) & 0xFF); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x08); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x10); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x18); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x20); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x28); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x30); llw |= ((long long int) (fgetc(file) & 0xFF) << 0x38); *value = llw; #endif } void sys_fread_int(int *value, FILE *file) { #ifndef WORDS_BIGENDIAN sys_fread(value, 1, sizeof(int), file); #else /* the following code is endianness neutral */ int dw = 0; dw = (int) (fgetc(file) & 0xFF); dw |= ((int) (fgetc(file) & 0xFF) << 0x08); dw |= ((int) (fgetc(file) & 0xFF) << 0x10); dw |= ((int) (fgetc(file) & 0xFF) << 0x18); *value = dw; #endif } void sys_fread_short(short *value, FILE *file) { #ifndef WORDS_BIGENDIAN sys_fread(value, 1, sizeof(short), file); #else /* the following code is endianness neutral */ short w = 0; w = (short) (fgetc(file) & 0xFF); w |= ((short) (fgetc(file) & 0xFF) << 0x08); *value = w; #endif } undbx-undbx-0.21/dbxsys.h000066400000000000000000000042241224265327600153720ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _DBX_SYS_H_ #define _DBX_SYS_H_ #include #include #ifdef __cplusplus extern "C" { #endif typedef unsigned long long int filetime_t; char **sys_glob(char *parent, char *pattern, int *num_files); void sys_glob_free(char **pglob); int sys_mkdir(char *parent, char *dir); int sys_chdir(char *dir); char *sys_getcwd(void); unsigned long long int sys_filesize(char *parent, char *filename); int sys_delete(char *parent, char *filename); int sys_move(char *parent, char *filename, char *destination); int sys_set_time(char *filename, time_t timestamp); int sys_set_filetime(char *filename, filetime_t filetime); char *sys_basename(char *path); char *sys_dirname(char *path); size_t sys_fread(void * ptr, size_t size, size_t nitems, FILE * stream); void sys_fread_long_long(long long int *value, FILE *file); void sys_fread_int(int *value, FILE *file); void sys_fread_short(short *value, FILE *file); #ifdef __cplusplus }; #endif #endif /* _DBX_SYS_H_ */ undbx-undbx-0.21/dist-win32.sh000077500000000000000000000051611224265327600161500ustar00rootroot00000000000000#! /bin/bash # UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. # Copyright (C) 2008-2013 Avi Rozen # # DBX file format parsing code is based on DbxConv - a DBX to MBOX # Converter. Copyright (C) 2008, 2009 Ulrich Krebs # # # RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - # a suite of utilities for electronic mail, Copyright (C) 2002, # 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. # # This file is part of UnDBX. # # UnDBX is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # This is a convenience script that I use to package UnDBX for MS-Windows # # Usage: ./dist-win32.sh [host] # # The default host is i686-w64-mingw32 which is the # MinGW win32 cross-compiler on Debian/testing (my dev box) # # For 64bit windows: # export ac_cv_func_realloc_0_nonnull=yes # export ac_cv_func_malloc_0_nonnull=yes # ./dist-win32.sh x86_64-w64-mingw32 # win32_host=${1:-i686-w64-mingw32} basedir=${0/%dist-win32.sh} cd "$basedir" autoreconf -vfi && find -maxdepth 1 -size 0 -exec rm -v {} \; cd - make distclean configure="$basedir""configure" distdir=$(eval "$configure --version" | head -1 | sed s/\ configure\ /-/) rm -rf ${distdir} ${distdir}.zip* ${distdir}.tar.gz* [ -f "$basedir"README.rst ] \ && rst2html "$basedir"README.rst > "$basedir"README.html \ && wikir "$basedir"README.rst > README.wiki mkdir ${distdir} win32_install_base=`cd ${distdir} && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && ${configure} --host=$win32_host --prefix="$win32_install_base" LDFLAGS=-s CFLAGS=-O3 \ && make dist-gzip \ && sha1sum ${distdir}.tar.gz > ${distdir}.tar.gz.sha1sum \ && make \ && make install \ && find ${distdir} -type f -exec mv -f {} ${distdir} \; \ && find ${distdir} -depth -type d -empty -exec rmdir -v {} \; \ && cp "$basedir"{README.html,COPYING} ${distdir} \ && zip -rq ${distdir}.zip ${distdir} \ && sha1sum ${distdir}.zip > ${distdir}.zip.sha1sum \ && rm -rf ${distdir} \ && make distclean undbx-undbx-0.21/emlread.c000066400000000000000000000470311224265327600154650ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include "emlread.h" enum { EOK = 0, EPARSE, ENOMEM, EBAD2047, EINVAL, EFULL }; static int _eml_str_append_n (char **to, const char *from, size_t n) { size_t l = 0; if (!to) return EOK; if (*to) { char *bigger; l = strlen (*to); bigger = realloc (*to, l + n + 1); if (!bigger) return ENOMEM; *to = bigger; } else *to = malloc (n + 1); strncpy (&to[0][l], from, n); to[0][l + n] = 0; return EOK; } static int _eml_str_append_char (char **to, char c) { return _eml_str_append_n (to, &c, 1); } static int _eml_str_append_range (char **to, const char *b, const char *e) { return _eml_str_append_n (to, b, e - b); } static void _eml_str_free (char **s) { if (s && *s) { free (*s); *s = 0; } } static int _eml_parse822_is_char (char c) { return isascii (c); } static int _eml_parse822_is_digit (char c) { return isdigit ((unsigned) c); } static int _eml_parse822_is_ctl (char c) { return iscntrl ((unsigned) c) || c == 127 /* DEL */ ; } static int _eml_parse822_is_space (char c) { return c == ' '; } static int _eml_parse822_is_htab (char c) { return c == '\t'; } static int _eml_parse822_is_lwsp_char (char c) { return _eml_parse822_is_space (c) || _eml_parse822_is_htab (c); } static int _eml_parse822_is_special (char c) { return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0; } static int _eml_parse822_is_atom_char_ex (char c) { return !_eml_parse822_is_special (c) && !_eml_parse822_is_space (c) && !_eml_parse822_is_ctl (c); } static int _eml_parse822_is_atom_char (char c) { return _eml_parse822_is_char (c) && _eml_parse822_is_atom_char_ex (c); } static int _eml_parse822_digits (const char **p, const char *e, int min, int max, int *digits) { const char *save = *p; int i = 0; *digits = 0; while (*p < e && _eml_parse822_is_digit (**p)) { *digits = *digits * 10 + **p - '0'; *p += 1; ++i; if (max != 0 && i == max) { break; } } if (i < min) { *p = save; return EPARSE; } return EOK; } static int _eml_parse822_skip_nl (const char **p, const char *e) { const char *s = *p; if ((&s[1] < e) && s[0] == '\r' && s[1] == '\n') { *p += 2; return EOK; } if ((&s[0] < e) && s[0] == '\n') { *p += 1; return EOK; } return EPARSE; } static int _eml_parse822_skip_lwsp_char (const char **p, const char *e) { if (*p < e && _eml_parse822_is_lwsp_char (**p)) { *p += 1; return EOK; } return EPARSE; } static int _eml_parse822_skip_lwsp (const char **p, const char *e) { int space = 0; while (*p != e) { const char *save = *p; if (_eml_parse822_skip_lwsp_char (p, e) == EOK) { space = 1; continue; } if (_eml_parse822_skip_nl (p, e) == EOK) { if (_eml_parse822_skip_lwsp_char (p, e) == EOK) continue; *p = save; return EPARSE; } break; } return space ? EOK : EPARSE; } static int _eml_parse822_quoted_pair (const char **p, const char *e, char **qpair) { int rc; if ((e - *p) < 2) return EPARSE; if (**p != '\\') return EPARSE; if ((rc = _eml_str_append_char (qpair, *(*p + 1)))) return rc; *p += 2; return EOK; } static int _eml_parse822_special (const char **p, const char *e, char c) { _eml_parse822_skip_lwsp (p, e); if ((*p != e) && **p == c) { *p += 1; return EOK; } return EPARSE; } static int _eml_parse822_comment (const char **p, const char *e, char **comment) { const char *save = *p; int rc; if ((rc = _eml_parse822_special (p, e, '('))) return rc; while (*p != e) { char c = **p; if (c == ')') { *p += 1; return EOK; } else if (c == '(') { rc = _eml_parse822_comment (p, e, comment); } else if (c == '\\'){ rc = _eml_parse822_quoted_pair (p, e, comment); } else if (c == '\r') { *p += 1; } else if (_eml_parse822_is_char (c)) { rc = _eml_str_append_char (comment, c); *p += 1; } else { *p += 1; } if (rc != EOK) break; } if (*p == e) rc = EPARSE; *p = save; return rc; } static int _eml_parse822_skip_comments (const char **p, const char *e) { int status; while ((status = _eml_parse822_comment (p, e, 0)) == EOK) ; return EOK; } static int _eml_parse822_atom (const char **p, const char *e, char **atom) { const char *save = *p; int rc = EPARSE; _eml_parse822_skip_comments (p, e); save = *p; while ((*p != e) && (**p == '.' || _eml_parse822_is_atom_char (**p))) { rc = _eml_str_append_char (atom, **p); *p += 1; if (rc != EOK) { *p = save; break; } } return rc; } static int _eml_parse822_day (const char **p, const char *e, int *day) { const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL }; int d; _eml_parse822_skip_comments (p, e); if ((e - *p) < 3) return EPARSE; for (d = 0; days[d]; d++) { if (strncasecmp (*p, days[d], 3) == 0) { *p += 3; if (day) *day = d; return EOK; } } return EPARSE; } static int _eml_parse822_date (const char **p, const char *e, int *day, int *mon, int *year) { const char *mons[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL }; const char *save = *p; int rc = EOK; int m = 0; int yr = 0; const char *yrbeg = 0; _eml_parse822_skip_comments (p, e); if ((rc = _eml_parse822_digits (p, e, 1, 2, day))) { *p = save; return rc; } _eml_parse822_skip_comments (p, e); if ((e - *p) < 3) return EPARSE; for (m = 0; mons[m]; m++) { if (strncasecmp (*p, mons[m], 3) == 0) { *p += 3; if (mon) *mon = m; break; } } if (!mons[m]) { *p = save; return EPARSE; } _eml_parse822_skip_comments (p, e); yrbeg = *p; if ((rc = _eml_parse822_digits (p, e, 2, 4, &yr))) { *p = save; return rc; } switch (*p - yrbeg) { case 2: if (yr >= 0 && yr <= 49) { yr += 2000; break; } case 3: yr += 1900; break; } if (year) *year = yr - 1900; return EOK; } static int _eml_parse822_time (const char **p, const char *e, int *hour, int *min, int *sec, int *tz, const char **tz_name) { struct { const char *tzname; int tz; } tzs[] = { { "UT", 0 * 60 * 60 }, { "UTC", 0 * 60 * 60 }, { "GMT", 0 * 60 * 60 }, { "EST", -5 * 60 * 60 }, { "EDT", -4 * 60 * 60 }, { "CST", -6 * 60 * 60 }, { "CDT", -5 * 60 * 60 }, { "MST", -7 * 60 * 60 }, { "MDT", -6 * 60 * 60 }, { "PST", -8 * 60 * 60 }, { "PDT", -7 * 60 * 60 }, { NULL, 0} }; const char *save = *p; int rc = EOK; int z = 0; char *zone = NULL; _eml_parse822_skip_comments (p, e); if ((rc = _eml_parse822_digits (p, e, 1, 2, hour))) { *p = save; return rc; } if ((rc = _eml_parse822_special (p, e, ':'))) { *p = save; return rc; } if ((rc = _eml_parse822_digits (p, e, 1, 2, min))) { *p = save; return rc; } if ((rc = _eml_parse822_special (p, e, ':'))) { *sec = 0; } else if ((rc = _eml_parse822_digits (p, e, 1, 2, sec))) { *p = save; return rc; } _eml_parse822_skip_comments (p, e); if ((rc = _eml_parse822_atom (p, e, &zone))) { if (tz) *tz = 0; return EOK; } for (; tzs[z].tzname; z++) { if (strcasecmp (zone, tzs[z].tzname) == 0) break; } if (tzs[z].tzname) { if (tz_name) *tz_name = tzs[z].tzname; if (tz) *tz = tzs[z].tz; } else if (strlen (zone) > 5 || strlen (zone) < 4) { if (*tz) *tz = 0; } else { int hh; int mm; int sign; char *zp = zone; switch (zp[0]) { case '-': sign = -1; zp++; break; case '+': sign = +1; zp++; break; default: sign = 1; break; } if (strspn (zp, "0123456789") == 4) { hh = (zone[1] - '0') * 10 + (zone[2] - '0'); mm = (zone[3] - '0') * 10 + (zone[4] - '0'); } else { hh = mm = 0; } if (tz) *tz = sign * (hh * 60 * 60 + mm * 60); } _eml_str_free (&zone); return EOK; } int _eml_parse822_date_time (const char **p, const char *e, struct tm *tm, time_t *ptzoffset) { const char *save = *p; int rc = 0; int wday = 0; int mday = 0; int mon = 0; int year = 0; int hour = 0; int min = 0; int sec = 0; int tzoffset = 0; const char *tz_name = 0; if ((rc = _eml_parse822_day (p, e, &wday))) { if (rc != EPARSE) return rc; } else { _eml_parse822_skip_comments (p, e); if ((rc = _eml_parse822_special (p, e, ','))) { *p = save; return rc; } } if ((rc = _eml_parse822_date (p, e, &mday, &mon, &year))) { *p = save; return rc; } if ((rc = _eml_parse822_time (p, e, &hour, &min, &sec, &tzoffset, &tz_name))) { *p = save; return rc; } if (tm) { memset (tm, 0, sizeof (*tm)); tm->tm_wday = wday; tm->tm_mday = mday; tm->tm_mon = mon; tm->tm_year = year; tm->tm_hour = hour; tm->tm_min = min; tm->tm_sec = sec; tm->tm_isdst = -1; } if (ptzoffset) *ptzoffset = tzoffset; return EOK; } static int _eml_parse822_field_name (const char **p, const char *e, char **fieldname) { const char *save = *p; char *fn = NULL; while (*p != e) { char c = **p; if (!_eml_parse822_is_char (c)) break; if (_eml_parse822_is_ctl (c)) break; if (_eml_parse822_is_space (c)) break; if (c == ':') break; _eml_str_append_char (&fn, c); *p += 1; } if (!fn) { *p = save; return EPARSE; } _eml_parse822_skip_comments (p, e); if (_eml_parse822_special (p, e, ':') != EOK) { *p = save; if (fn) free (fn); return EPARSE; } *fieldname = fn; return EOK; } static int _eml_parse822_field_body (const char **p, const char *e, char **fieldbody) { char *fb = NULL; for (;;) { const char *bol = *p; const char *eol = NULL; while (bol != e) { if (!_eml_parse822_is_lwsp_char(*bol)) break; ++bol; } eol = bol; while (eol != e) { if (eol[0] == '\r' && (eol + 1) != e && eol[1] == '\n') break; ++eol; } _eml_str_append_range (&fb, bol, eol); *p = eol; if (eol == e) break; *p += 2; if (*p == e) break; if (**p != ' ' && **p != '\t') break; } *fieldbody = fb; return EOK; } static int _eml_b64_input (char c) { const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int i; for (i = 0; i < 64; i++) { if (table[i] == c) return i; } return -1; } static int _eml_base64_decode (const char *iptr, size_t isize, char *optr, size_t osize, size_t *nbytes) { int i = 0, tmp = 0, pad = 0; size_t consumed = 0; unsigned char data[4]; *nbytes = 0; while (consumed < isize && (*nbytes)+3 < osize) { while (( i < 4 ) && (consumed < isize)) { tmp = _eml_b64_input (*iptr++); consumed++; if (tmp != -1) data[i++] = tmp; else if (*(iptr-1) == '=') { data[i++] = '\0'; pad++; } } if (i == 4) { *optr++ = (data[0] << 2) | ((data[1] & 0x30) >> 4); *optr++ = ((data[1] & 0xf) << 4) | ((data[2] & 0x3c) >> 2); *optr++ = ((data[2] & 0x3) << 6) | data[3]; (*nbytes) += 3 - pad; } else { consumed -= i; return consumed; } i = 0; } return consumed; } static int _eml_q_decode (const char *iptr, size_t isize, char *optr, size_t osize, size_t *nbytes) { char c; size_t consumed = 0; *nbytes = 0; while (consumed < isize && *nbytes < osize) { c = *iptr++; if (c == '=') { if (consumed + 2 >= isize) break; else { char chr[3]; int new_c; chr[2] = 0; chr[0] = *iptr++; if (chr[0] != '\n') { chr[1] = *iptr++; new_c = strtoul (chr, NULL, 16); *optr++ = new_c; (*nbytes)++; consumed += 3; } else consumed += 2; } } else if (c == '\r') { if (consumed + 1 >= isize) break; else { iptr++; *optr++ = '\n'; (*nbytes)++; consumed += 2; } } else if (c == '_') { *optr++ = ' '; (*nbytes)++; consumed++; } else { *optr++ = c; (*nbytes)++; consumed++; } } return consumed; } static int _eml_realloc_buffer (char **bufp, size_t *bufsizep, size_t incr) { size_t newsize = *bufsizep + incr; char *newp = realloc (*bufp, newsize); if (newp == NULL) return 1; *bufp = newp; *bufsizep = newsize; return 0; } static int _eml_getword (char **pret, const char **pstr, int delim) { size_t len; char *ret; const char *start = *pstr; const char *end = strchr (start, delim); free (*pret); *pret = NULL; if (!end) return EBAD2047; len = end - start; ret = malloc (len + 1); if (!ret) return ENOMEM; memcpy (ret, start, len); ret[len] = 0; *pstr = end + 1; *pret = ret; return 0; } static int _eml_rfc2047_decode (const char *input, char **ptostr) { int status = 0; const char *fromstr; char *buffer; size_t bufsize; size_t bufpos; size_t run_count = 0; char *fromcode = NULL; char *encoding_type = NULL; char *encoded_text = NULL; char *decoded_text = NULL; #define BUFINC 128 #define CHKBUF(count) do { \ if (bufpos+count >= bufsize) \ { \ size_t s = bufpos + count - bufsize; \ if (s < BUFINC) \ s = BUFINC; \ if (_eml_realloc_buffer (&buffer, &bufsize, s)) \ { \ free (buffer); \ free (fromcode); \ free (encoding_type); \ free (encoded_text); \ return ENOMEM; \ } \ } \ } while (0) if (!input) return EINVAL; if (!ptostr) return EFULL; fromstr = input; bufsize = strlen (fromstr) + 1; buffer = malloc (bufsize); if (buffer == NULL) return ENOMEM; bufpos = 0; while (*fromstr) { if (strncmp (fromstr, "=?", 2) == 0) { int decoded = 0; size_t nbytes = 0; size_t size; const char *sp = fromstr + 2; if (decoded_text) free(decoded_text); decoded_text = NULL; status = _eml_getword (&fromcode, &sp, '?'); if (status) break; status = _eml_getword (&encoding_type, &sp, '?'); if (status) break; status = _eml_getword (&encoded_text, &sp, '?'); if (status) break; if (sp == NULL || sp[0] != '=') { status = EBAD2047; break; } size = strlen (encoded_text); decoded_text = (char *)calloc(size, sizeof(char)); switch (encoding_type[0]) { case 'b': case 'B': decoded = (_eml_base64_decode(encoded_text, size, decoded_text, size, &nbytes) && nbytes); break; case 'q': case 'Q': decoded = (_eml_q_decode(encoded_text, size, decoded_text, size, &nbytes) && nbytes); break; default: status = EBAD2047; break; } if (status != 0) break; if (decoded) { CHKBUF (nbytes); memcpy (buffer + bufpos, decoded_text, nbytes); bufpos += nbytes; } fromstr = sp + 1; run_count = 1; } else if (run_count) { if (*fromstr == ' ' || *fromstr == '\t') { run_count++; fromstr++; continue; } else { if (--run_count) { CHKBUF (run_count); memcpy (buffer + bufpos, fromstr - run_count, run_count); bufpos += run_count; run_count = 0; } CHKBUF (1); buffer[bufpos++] = *fromstr++; } } else { CHKBUF (1); buffer[bufpos++] = *fromstr++; } } if (decoded_text) free(decoded_text); if (*fromstr) { size_t len = strlen (fromstr); CHKBUF (len); memcpy (buffer + bufpos, fromstr, len); bufpos += len; } CHKBUF (1); buffer[bufpos++] = 0; free (fromcode); free (encoding_type); free (encoded_text); *ptostr = realloc (buffer, bufpos); return status; } static time_t _eml_mktime_tz(struct tm *tm, int tzoffset) { time_t t; /* utc time */ int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; if (m < 3) { m += 12; y--; } t = 86400 * (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; return t - tzoffset; } void eml_parse(char *message, char **subject, char **from, char **to, time_t *timestamp) { char *pmessage = message; char *pstop = pmessage + strlen(pmessage); char *pname = NULL; char *pbody = NULL; while (_eml_parse822_field_name((const char **)&pmessage, pstop, &pname) == EOK && _eml_parse822_field_body((const char **)&pmessage, pstop, &pbody) == EOK) { /* printf("\033[1;31;48m%s\033[0m: \"%s\"\n", pname, pbody); */ if (strcasecmp(pname, "subject") == 0) { if (_eml_rfc2047_decode(pbody, subject) != EOK) { free(*subject); *subject = NULL; } } else if (strcasecmp(pname, "from") == 0) { if (_eml_rfc2047_decode(pbody, from) != EOK) { free(*from); *from = NULL; } } else if (strcasecmp(pname, "to") == 0) { if (_eml_rfc2047_decode(pbody, to) != EOK) { free(*to); *to = NULL; } } else if (strcasecmp(pname, "date") == 0) { char *pdate = pbody; struct tm tm; time_t tzoffset = 0; if (_eml_parse822_date_time((const char **)&pdate, pbody + strlen(pbody), &tm, &tzoffset) == EOK) *timestamp = _eml_mktime_tz(&tm, tzoffset); } free(pbody); free(pname); } } undbx-undbx-0.21/emlread.h000066400000000000000000000026331224265327600154710ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _EML_READ_H_ #define _EML_READ_H_ #ifdef __cplusplus extern "C" { #endif #include "dbxsys.h" void eml_parse(char *message, char **subject, char **from, char **to, time_t *timestamp); #ifdef __cplusplus }; #endif #endif /* _EML_READ_H_ */ undbx-undbx-0.21/undbx.c000066400000000000000000000411031224265327600151660ustar00rootroot00000000000000/* UnDBX - Tool to extract e-mail messages from Outlook Express DBX files. Copyright (C) 2008-2013 Avi Rozen DBX file format parsing code is based on DbxConv - a DBX to MBOX Converter. Copyright (C) 2008, 2009 Ulrich Krebs RFC-2822 and RFC-2047 parsing code is adapted from GNU Mailutils - a suite of utilities for electronic mail, Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of UnDBX. UnDBX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H # include # define DBX_VERSION PACKAGE_VERSION #endif #include #include #include #include #include #include "dbxread.h" typedef enum { DBX_SAVE_NOOP, DBX_SAVE_OK, DBX_SAVE_ERROR } dbx_save_status_t; typedef enum { DBX_EXTRACT_IGNORE, DBX_EXTRACT_FORCE, DBX_EXTRACT_MAYBE } dbx_extract_decision_t; static int _str_cmp(const char **ia, const char **ib) { return strcmp(*ia, *ib); } static int _dbx_offset_cmp(const dbx_info_t *ia, const dbx_info_t *ib) { return (ia->offset - ib->offset); } static dbx_save_status_t _save_message(char *dir, char *filename, char *message, unsigned int size) { FILE *eml = NULL; char *cwd = NULL; size_t b = 0; int rc = 0; cwd = sys_getcwd(); if (cwd == NULL) { perror("_save_message (sys_getcwd)"); return DBX_SAVE_ERROR; } rc = sys_chdir(dir); if (rc != 0) { perror("_save_message (sys_chdir)"); return DBX_SAVE_ERROR; } eml = fopen(filename, "w+b"); sys_chdir(cwd); free(cwd); cwd = NULL; if (eml == NULL) { perror("_save_message (fopen)"); return DBX_SAVE_ERROR; } b = fwrite(message, 1, size, eml); if (b != size) { perror("_save_message (fwrite)"); return DBX_SAVE_ERROR; } fclose(eml); return DBX_SAVE_OK; } static void _set_message_time(char *dir, char *filename, time_t timestamp) { char *cwd = NULL; int rc = 0; cwd = sys_getcwd(); if (cwd == NULL) { perror("_set_message_time (sys_getcwd)"); return; } rc = sys_chdir(dir); if (rc != 0) { perror("_set_message_time (sys_chdir)"); return; } sys_set_time(filename, timestamp); sys_chdir(cwd); free(cwd); cwd = NULL; } static void _set_message_filetime(dbx_info_t *info, char *dir) { char *cwd = NULL; int rc = 0; filetime_t filetime = 0; cwd = sys_getcwd(); if (cwd == NULL) { perror("_set_message_filetime (sys_getcwd)"); return; } rc = sys_chdir(dir); if (rc != 0) { perror("_set_message_filetime (sys_chdir)"); return; } filetime = info->send_create_time? info->send_create_time : info->receive_create_time; sys_set_filetime(info->filename, filetime); sys_chdir(cwd); free(cwd); cwd = NULL; } static dbx_save_status_t _maybe_save_message(dbx_t *dbx, int imessage, char *dir, int force) { dbx_save_status_t status = DBX_SAVE_NOOP; dbx_info_t *info = dbx->info + imessage; unsigned long long int size = 0; unsigned int message_size = 0; char *message = NULL; if (!force) size = sys_filesize(dir, info->filename); if (force || (info->valid & DBX_MASK_MSGSIZE) == 0 || size != info->message_size) { message = dbx_message(dbx, imessage, &message_size); if (force || (size != message_size)) { status = _save_message(dir, info->filename, message, message_size); switch (status) { case DBX_SAVE_ERROR: dbx_progress_update(dbx->progress_handle, DBX_STATUS_ERROR, imessage, "%s", info->filename); break; case DBX_SAVE_OK: _set_message_filetime(info, dir); dbx_progress_update(dbx->progress_handle, DBX_STATUS_OK, imessage, "%s", info->filename); break; default: break; } } free(message); } return status; } static void _recover(dbx_t *dbx, char *out_dir, char *eml_dir, int *saved, int *errors) { int i = 0; const char *scan_type[2] = { "messages", "deleted message fragments" }; for(i = 0; i < dbx->scan_count; i++) { int s = 0; int e = 0; dbx_save_status_t status = DBX_SAVE_NOOP; int imessage = 0; char *message = NULL; char *filename = NULL; unsigned int size = 0; time_t timestamp = 0; if (dbx->scan[i].count > 0) { char *dest_dir = strdup(eml_dir); if (dbx->scan[i].deleted) { dest_dir = (char *)realloc(dest_dir, sizeof(char) * (strlen(dest_dir) + strlen("/deleted") + 1)); strcat(dest_dir, "/deleted"); } dbx_progress_push(dbx->progress_handle, DBX_VERBOSITY_INFO, dbx->scan[i].count, "Recovering %d %s with offset %" #ifndef WIN32 "ll" #else "I64" #endif "d from %s to %s/%s", dbx->scan[i].count, scan_type[dbx->scan[i].deleted], dbx->scan[i].offset, dbx->filename, out_dir, dest_dir); if (dbx->scan[i].deleted) { int rc = sys_mkdir(eml_dir, "deleted"); if (rc != 0) { perror("_recover (sys_mkdir)"); break; } } for (imessage = 0; imessage < dbx->scan[i].count; imessage++) { message = dbx_recover_message(dbx, i, imessage, &size, ×tamp, &filename); if (message) { status = _save_message(dest_dir, filename, message, size); switch (status) { case DBX_SAVE_ERROR: e++; dbx_progress_update(dbx->progress_handle, DBX_STATUS_ERROR, imessage, "%s", filename); break; case DBX_SAVE_OK: s++; _set_message_time(dest_dir, filename, timestamp); dbx_progress_update(dbx->progress_handle, DBX_STATUS_OK, imessage, "%s", filename); break; default: break; } } free(filename); free(message); } free(dest_dir); dbx_progress_pop(dbx->progress_handle, "%d %s recovered, %d errors", s, scan_type[dbx->scan[i].deleted], e); } *saved += s; *errors += e; } } static void _extract(dbx_t *dbx, char *out_dir, char *eml_dir, int *saved, int *deleted, int *errors) { int no_more_messages = 0; int no_more_files = 0; char **eml_files = NULL; int num_eml_files = 0; int imessage = 0; int ifile = 0; dbx_progress_push(dbx->progress_handle, DBX_VERBOSITY_INFO, dbx->message_count, "Extracting %d messages from %s to %s/%s", dbx->message_count, dbx->filename, out_dir, eml_dir); eml_files = sys_glob(eml_dir, "*.eml", &num_eml_files); no_more_messages = (imessage == dbx->message_count); no_more_files = (ifile == num_eml_files); qsort(eml_files, num_eml_files, sizeof(char *), (dbx_cmpfunc_t) _str_cmp); if (!dbx->options->delete_deleted) { int rc = sys_mkdir(eml_dir, "deleted"); if (rc != 0) { perror("_extract (sys_mkdir)"); return; } } while (!no_more_messages || !no_more_files) { int cond; int ignore; ignore = (dbx->options->ignore0 && !no_more_messages && dbx->info[imessage].offset == 0); if (!no_more_messages && !no_more_files) { cond = strcmp(dbx->info[imessage].filename, eml_files[ifile]); if (ignore && cond == 0) { cond = 1; imessage++; } } else if (no_more_files) cond = -1; else cond = 1; if (!no_more_messages) dbx->info[imessage].extract = DBX_EXTRACT_IGNORE; if (cond < 0) { /* message not found on disk: extract from dbx */ if (!ignore) dbx->info[imessage].extract = DBX_EXTRACT_FORCE; imessage++; } else if (cond == 0) { /* message found on disk: extract from dbx if modified */ dbx->info[imessage].extract = DBX_EXTRACT_MAYBE; imessage++; ifile++; } else { /* file on disk not found in dbx: move it to 'deleted' sub-folder or delete from disk */ if (!dbx->options->delete_deleted) { int rc = sys_move(eml_dir, eml_files[ifile], "deleted"); if (rc != 0) perror("_extract (sys_move)"); dbx_progress_update(dbx->progress_handle, DBX_STATUS_MOVED, -1, "%s", eml_files[ifile]); } else { int rc = sys_delete(eml_dir, eml_files[ifile]); if (rc != 0) perror("_extract (sys_delete)"); dbx_progress_update(dbx->progress_handle, DBX_STATUS_DELETED, -1, "%s", eml_files[ifile]); } ifile++; (*deleted)++; } no_more_messages = (imessage == dbx->message_count); no_more_files = (ifile == num_eml_files); } /* sort entries by offset: should make extraction faster in most cases */ qsort(dbx->info, dbx->message_count, sizeof(dbx_info_t), (dbx_cmpfunc_t) _dbx_offset_cmp); for(imessage = 0; imessage < dbx->message_count; imessage++) { dbx_save_status_t status = DBX_SAVE_NOOP; switch (dbx->info[imessage].extract) { case DBX_EXTRACT_IGNORE: break; case DBX_EXTRACT_FORCE: status = _maybe_save_message(dbx, imessage, eml_dir, 1); break; case DBX_EXTRACT_MAYBE: status = _maybe_save_message(dbx, imessage, eml_dir, 0); break; } if (status == DBX_SAVE_OK) (*saved)++; if (status == DBX_SAVE_ERROR) (*errors)++; } dbx_progress_pop(dbx->progress_handle, "%d messages saved, %d skipped, %d errors, %d files %s", *saved, dbx->message_count - *saved - *errors, *errors, *deleted, !dbx->options->delete_deleted? "moved":"deleted"); sys_glob_free(eml_files); } static int _undbx(char *dbx_dir, char *out_dir, char *dbx_file, dbx_options_t *options) { int deleted = 0; int saved = 0; int errors = 0; dbx_t *dbx = NULL; char *eml_dir = NULL; char *cwd = NULL; int rc = -1; cwd = sys_getcwd(); if (cwd == NULL) { dbx_progress_message(NULL, DBX_STATUS_ERROR, "can't get current working directory"); goto UNDBX_DONE; } rc = sys_chdir(dbx_dir); if (rc != 0) { dbx_progress_message(NULL, DBX_STATUS_ERROR, "can't chdir to %s", dbx_dir); goto UNDBX_DONE; } dbx = dbx_open(dbx_file, options); sys_chdir(cwd); if (dbx == NULL) { dbx_progress_message(NULL, DBX_STATUS_WARNING, "can't open DBX file %s", dbx_file); rc = -1; goto UNDBX_DONE; } if (!options->recover && dbx->type != DBX_TYPE_EMAIL) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING, "DBX file %s does not contain messages", dbx_file); rc = -1; goto UNDBX_DONE; } if (!options->recover && dbx->file_size >= 0x80000000) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING,"DBX file %s is corrupted (larger than 2GB)", dbx_file); } eml_dir = strdup(dbx_file); eml_dir[strlen(eml_dir) - 4] = '\0'; rc = sys_mkdir(out_dir, eml_dir); if (rc != 0) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_ERROR, "can't create directory %s/%s", out_dir, eml_dir); goto UNDBX_DONE; } rc = sys_chdir(out_dir); if (rc != 0) { dbx_progress_message(dbx->progress_handle, DBX_STATUS_ERROR, "can't chdir to %s", out_dir); goto UNDBX_DONE; } if (options->recover) _recover(dbx, out_dir, eml_dir, &saved, &errors); else _extract(dbx, out_dir, eml_dir, &saved, &deleted, &errors); UNDBX_DONE: free(eml_dir); eml_dir = NULL; dbx_close(dbx); sys_chdir(cwd); free(cwd); cwd = NULL; return rc; } static char **_get_files(char **dir, int *num_files) { char **files = NULL; int l = strlen(*dir); files = sys_glob(*dir, "*.dbx", num_files); if (*num_files == 0 && l > 4 && strcasecmp(*dir + l - 4, ".dbx") == 0) { char *dirname = NULL; sys_glob_free(files); files = (char **)calloc(2, sizeof(char *)); files[0] = strdup(sys_basename(*dir)); *num_files = 1; dirname = strdup(sys_dirname(*dir)); free(*dir); *dir = dirname; } return files; } static void _usage(char *prog, int rc) { FILE *stream = (rc == EXIT_SUCCESS)? stdout:stderr; fprintf(stream, "Usage: %s [