mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
feat: import mmime crate
This commit is contained in:
committed by
GitHub
parent
321c5e049b
commit
cb784615ee
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -502,7 +502,7 @@ dependencies = [
|
|||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mmime 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mmime 0.1.2",
|
||||||
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -1258,7 +1258,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "mmime"
|
name = "mmime"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"charset 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"charset 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -3056,7 +3055,6 @@ dependencies = [
|
|||||||
"checksum miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7108aff85b876d06f22503dcce091e29f76733b2bfdd91eebce81f5e68203a10"
|
"checksum miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7108aff85b876d06f22503dcce091e29f76733b2bfdd91eebce81f5e68203a10"
|
||||||
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
|
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
|
||||||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||||
"checksum mmime 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "befb13ecb83a4344d5c268a36463fc1b3526a78bfded316ddfaa955b5d018b91"
|
|
||||||
"checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e"
|
"checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e"
|
||||||
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
||||||
"checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b"
|
"checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b"
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ license = "MPL"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deltachat_derive = { path = "./deltachat_derive" }
|
deltachat_derive = { path = "./deltachat_derive" }
|
||||||
|
mmime = { version = "0.1.2", path = "./mmime" }
|
||||||
|
|
||||||
libc = "0.2.51"
|
libc = "0.2.51"
|
||||||
pgp = { version = "0.2", default-features = false }
|
pgp = { version = "0.2", default-features = false }
|
||||||
hex = "0.3.2"
|
hex = "0.3.2"
|
||||||
@@ -20,7 +22,6 @@ num-traits = "0.2.6"
|
|||||||
native-tls = "0.2.3"
|
native-tls = "0.2.3"
|
||||||
lettre = "0.9.0"
|
lettre = "0.9.0"
|
||||||
imap = { git = "https://github.com/jonhoo/rust-imap", rev = "281d2eb8ab50dc656ceff2ae749ca5045f334e15" }
|
imap = { git = "https://github.com/jonhoo/rust-imap", rev = "281d2eb8ab50dc656ceff2ae749ca5045f334e15" }
|
||||||
mmime = "0.1.2"
|
|
||||||
base64 = "0.10"
|
base64 = "0.10"
|
||||||
charset = "0.1"
|
charset = "0.1"
|
||||||
percent-encoding = "2.0"
|
percent-encoding = "2.0"
|
||||||
@@ -59,6 +60,7 @@ proptest = "0.9.4"
|
|||||||
members = [
|
members = [
|
||||||
"deltachat-ffi",
|
"deltachat-ffi",
|
||||||
"deltachat_derive",
|
"deltachat_derive",
|
||||||
|
"mmime",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ install:
|
|||||||
build: false
|
build: false
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- cargo test --release
|
- cargo test --release --all
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
- target
|
- target
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ fi
|
|||||||
if [[ $NORUN == "1" ]]; then
|
if [[ $NORUN == "1" ]]; then
|
||||||
export CARGO_SUBCMD="build"
|
export CARGO_SUBCMD="build"
|
||||||
else
|
else
|
||||||
export CARGO_SUBCMD="test"
|
export CARGO_SUBCMD="test --all"
|
||||||
export OPT="${OPT} "
|
export OPT="${OPT} "
|
||||||
export OPT_RELEASE="${OPT_RELEASE} "
|
export OPT_RELEASE="${OPT_RELEASE} "
|
||||||
export OPT_RELEASE_IGNORED="${OPT_RELEASE} -- --ignored"
|
export OPT_RELEASE_IGNORED="${OPT_RELEASE} -- --ignored"
|
||||||
@@ -39,4 +39,5 @@ fi
|
|||||||
|
|
||||||
# Run all the test configurations:
|
# Run all the test configurations:
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT
|
$CARGO_CMD $CARGO_SUBCMD $OPT
|
||||||
|
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE_IGNORED
|
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE_IGNORED
|
||||||
|
|||||||
42
mmime/.circleci/config.yml
Normal file
42
mmime/.circleci/config.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# copied from http://koushiro.me/2019/04/30/Building-and-Testing-Rust-projects-on-CircleCI/
|
||||||
|
|
||||||
|
version: 2.1
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: ubuntu:18.04
|
||||||
|
|
||||||
|
working_directory: ~/deltachat-core-rust
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
|
||||||
|
- run:
|
||||||
|
name: Setup build environment
|
||||||
|
command: |
|
||||||
|
apt update
|
||||||
|
apt install -y curl build-essential autoconf libtool git python pkg-config
|
||||||
|
# this will pick default toolchain from `rust-toolchain` file
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y;
|
||||||
|
source $HOME/.cargo/env
|
||||||
|
no_output_timeout: 1800s
|
||||||
|
|
||||||
|
- run:
|
||||||
|
name: Format
|
||||||
|
command: |
|
||||||
|
export PATH=~/.cargo/bin:$PATH
|
||||||
|
rustup component add rustfmt
|
||||||
|
cargo fmt -- --check
|
||||||
|
|
||||||
|
- run:
|
||||||
|
name: Test
|
||||||
|
command: |
|
||||||
|
export PATH=~/.cargo/bin:$PATH
|
||||||
|
export RUST_BACKTRACE=1
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
workflows:
|
||||||
|
version: 2.1
|
||||||
|
build:
|
||||||
|
jobs:
|
||||||
|
- build
|
||||||
23
mmime/Cargo.toml
Normal file
23
mmime/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[package]
|
||||||
|
name = "mmime"
|
||||||
|
version = "0.1.2"
|
||||||
|
authors = ["dignifiedquire <dignifiedquire@users.noreply.github.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
homepage = "https://github.com/deltachat/deltachat-core-rust"
|
||||||
|
repository = "https://github.com/deltachat/deltachat-core-rust"
|
||||||
|
readme = "README.md"
|
||||||
|
description = "Mime parsing for email"
|
||||||
|
|
||||||
|
|
||||||
|
keywords = ["mail", "mim", "email", "imap", "smtp"]
|
||||||
|
categories = ["std", "email"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libc = "0.2.54"
|
||||||
|
charset = "0.1.2"
|
||||||
|
memmap = "0.7.0"
|
||||||
|
lazy_static = "1.3.0"
|
||||||
|
rand = "0.6.5"
|
||||||
|
chrono = "0.4.6"
|
||||||
|
hex = "0.3.2"
|
||||||
201
mmime/LICENSE-APACHE
Normal file
201
mmime/LICENSE-APACHE
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
23
mmime/LICENSE-MIT
Normal file
23
mmime/LICENSE-MIT
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
Permission is hereby granted, free of charge, to any
|
||||||
|
person obtaining a copy of this software and associated
|
||||||
|
documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without
|
||||||
|
limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software
|
||||||
|
is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice
|
||||||
|
shall be included in all copies or substantial portions
|
||||||
|
of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||||
|
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
4
mmime/LICENSE.md
Normal file
4
mmime/LICENSE.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
This library is primarly distributed under the terms of both the MIT license and
|
||||||
|
the Apache License (Version 2.0).
|
||||||
|
|
||||||
|
See LICENSE-MIT and LICENSE-APACHE for details.
|
||||||
16
mmime/README.md
Normal file
16
mmime/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# mmime
|
||||||
|
|
||||||
|
[![CircleCI build status][circle-shield]][circle] [![Appveyor build status][appveyor-shield]][appveyor] [![License][license-shield]][license]
|
||||||
|
|
||||||
|
> mmmmmmime parsing
|
||||||
|
|
||||||
|
Base code was compiled using c2rust from libetpan.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[circle-shield]: https://img.shields.io/circleci/project/github/dignifiedquire/mmime/master.svg?style=flat-square
|
||||||
|
[circle]: https://circleci.com/gh/dignifiedquire/mmime/
|
||||||
|
[appveyor-shield]: https://ci.appveyor.com/api/projects/status/l26co5rba32knrlu/branch/master?style=flat-square
|
||||||
|
[appveyor]: https://ci.appveyor.com/project/dignifiedquire/mmime/branch/master
|
||||||
|
[license-shield]: https://img.shields.io/badge/License-MIT%2FApache2.0-green.svg?style=flat-square
|
||||||
|
[license]: https://github.com/rpgp/rpgp/blob/master/LICENSE.md
|
||||||
32
mmime/src/charconv.rs
Normal file
32
mmime/src/charconv.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use crate::other::*;
|
||||||
|
use libc;
|
||||||
|
use std::ffi::{CStr, CString};
|
||||||
|
|
||||||
|
pub const MAIL_CHARCONV_ERROR_CONV: libc::c_uint = 3;
|
||||||
|
pub const MAIL_CHARCONV_ERROR_MEMORY: libc::c_uint = 2;
|
||||||
|
pub const MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: libc::c_uint = 1;
|
||||||
|
pub const MAIL_CHARCONV_NO_ERROR: libc::c_uint = 0;
|
||||||
|
|
||||||
|
pub unsafe fn charconv(
|
||||||
|
tocode: *const libc::c_char,
|
||||||
|
fromcode: *const libc::c_char,
|
||||||
|
s: *const libc::c_char,
|
||||||
|
length: size_t,
|
||||||
|
result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
assert!(!fromcode.is_null(), "invalid fromcode");
|
||||||
|
assert!(!s.is_null(), "invalid input string");
|
||||||
|
if let Some(encoding) =
|
||||||
|
charset::Charset::for_label(CStr::from_ptr(fromcode).to_str().unwrap().as_bytes())
|
||||||
|
{
|
||||||
|
let data = std::slice::from_raw_parts(s as *const u8, strlen(s));
|
||||||
|
|
||||||
|
let (res, _, _) = encoding.decode(data);
|
||||||
|
let res_c = CString::new(res.as_bytes()).unwrap();
|
||||||
|
*result = strdup(res_c.as_ptr()) as *mut _;
|
||||||
|
|
||||||
|
MAIL_CHARCONV_NO_ERROR as libc::c_int
|
||||||
|
} else {
|
||||||
|
MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET as libc::c_int
|
||||||
|
}
|
||||||
|
}
|
||||||
427
mmime/src/chash.rs
Normal file
427
mmime/src/chash.rs
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
use libc;
|
||||||
|
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct chashdatum {
|
||||||
|
pub data: *mut libc::c_void,
|
||||||
|
pub len: libc::c_uint,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct chash {
|
||||||
|
pub size: libc::c_uint,
|
||||||
|
pub count: libc::c_uint,
|
||||||
|
pub copyvalue: libc::c_int,
|
||||||
|
pub copykey: libc::c_int,
|
||||||
|
pub cells: *mut *mut chashcell,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct chashcell {
|
||||||
|
pub func: libc::c_uint,
|
||||||
|
pub key: chashdatum,
|
||||||
|
pub value: chashdatum,
|
||||||
|
pub next: *mut chashcell,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type chashiter = chashcell;
|
||||||
|
/* Allocates a new (empty) hash using this initial size and the given flags,
|
||||||
|
specifying which data should be copied in the hash.
|
||||||
|
CHASH_COPYNONE : Keys/Values are not copied.
|
||||||
|
CHASH_COPYKEY : Keys are dupped and freed as needed in the hash.
|
||||||
|
CHASH_COPYVALUE : Values are dupped and freed as needed in the hash.
|
||||||
|
CHASH_COPYALL : Both keys and values are dupped in the hash.
|
||||||
|
*/
|
||||||
|
pub unsafe fn chash_new(mut size: libc::c_uint, mut flags: libc::c_int) -> *mut chash {
|
||||||
|
let mut h: *mut chash = 0 as *mut chash;
|
||||||
|
h = malloc(::std::mem::size_of::<chash>() as libc::size_t) as *mut chash;
|
||||||
|
if h.is_null() {
|
||||||
|
return 0 as *mut chash;
|
||||||
|
}
|
||||||
|
if size < 13i32 as libc::c_uint {
|
||||||
|
size = 13i32 as libc::c_uint
|
||||||
|
}
|
||||||
|
(*h).count = 0i32 as libc::c_uint;
|
||||||
|
(*h).cells = calloc(
|
||||||
|
size as libc::size_t,
|
||||||
|
::std::mem::size_of::<*mut chashcell>() as libc::size_t,
|
||||||
|
) as *mut *mut chashcell;
|
||||||
|
if (*h).cells.is_null() {
|
||||||
|
free(h as *mut libc::c_void);
|
||||||
|
return 0 as *mut chash;
|
||||||
|
}
|
||||||
|
(*h).size = size;
|
||||||
|
(*h).copykey = flags & 1i32;
|
||||||
|
(*h).copyvalue = flags & 2i32;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Frees a hash */
|
||||||
|
pub unsafe fn chash_free(mut hash: *mut chash) {
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut next: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
indx = 0i32 as libc::c_uint;
|
||||||
|
while indx < (*hash).size {
|
||||||
|
iter = *(*hash).cells.offset(indx as isize);
|
||||||
|
while !iter.is_null() {
|
||||||
|
next = (*iter).next;
|
||||||
|
if 0 != (*hash).copykey {
|
||||||
|
free((*iter).key.data);
|
||||||
|
}
|
||||||
|
if 0 != (*hash).copyvalue {
|
||||||
|
free((*iter).value.data);
|
||||||
|
}
|
||||||
|
free(iter as *mut libc::c_void);
|
||||||
|
iter = next
|
||||||
|
}
|
||||||
|
indx = indx.wrapping_add(1)
|
||||||
|
}
|
||||||
|
free((*hash).cells as *mut libc::c_void);
|
||||||
|
free(hash as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Removes all elements from a hash */
|
||||||
|
pub unsafe fn chash_clear(mut hash: *mut chash) {
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut next: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
indx = 0i32 as libc::c_uint;
|
||||||
|
while indx < (*hash).size {
|
||||||
|
iter = *(*hash).cells.offset(indx as isize);
|
||||||
|
while !iter.is_null() {
|
||||||
|
next = (*iter).next;
|
||||||
|
if 0 != (*hash).copykey {
|
||||||
|
free((*iter).key.data);
|
||||||
|
}
|
||||||
|
if 0 != (*hash).copyvalue {
|
||||||
|
free((*iter).value.data);
|
||||||
|
}
|
||||||
|
free(iter as *mut libc::c_void);
|
||||||
|
iter = next
|
||||||
|
}
|
||||||
|
indx = indx.wrapping_add(1)
|
||||||
|
}
|
||||||
|
memset(
|
||||||
|
(*hash).cells as *mut libc::c_void,
|
||||||
|
0i32,
|
||||||
|
((*hash).size as libc::size_t)
|
||||||
|
.wrapping_mul(::std::mem::size_of::<*mut chashcell>() as libc::size_t),
|
||||||
|
);
|
||||||
|
(*hash).count = 0i32 as libc::c_uint;
|
||||||
|
}
|
||||||
|
/* Adds an entry in the hash table.
|
||||||
|
Length can be 0 if key/value are strings.
|
||||||
|
If an entry already exists for this key, it is replaced, and its value
|
||||||
|
is returned. Otherwise, the data pointer will be NULL and the length
|
||||||
|
field be set to TRUE or FALSe to indicate success or failure. */
|
||||||
|
pub unsafe fn chash_set(
|
||||||
|
mut hash: *mut chash,
|
||||||
|
mut key: *mut chashdatum,
|
||||||
|
mut value: *mut chashdatum,
|
||||||
|
mut oldvalue: *mut chashdatum,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut current_block: u64;
|
||||||
|
let mut func: libc::c_uint = 0;
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut cell: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
if (*hash).count > (*hash).size.wrapping_mul(3i32 as libc::c_uint) {
|
||||||
|
r = chash_resize(
|
||||||
|
hash,
|
||||||
|
(*hash)
|
||||||
|
.count
|
||||||
|
.wrapping_div(3i32 as libc::c_uint)
|
||||||
|
.wrapping_mul(2i32 as libc::c_uint)
|
||||||
|
.wrapping_add(1i32 as libc::c_uint),
|
||||||
|
);
|
||||||
|
if r < 0i32 {
|
||||||
|
current_block = 17701753836843438419;
|
||||||
|
} else {
|
||||||
|
current_block = 7095457783677275021;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_block = 7095457783677275021;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
7095457783677275021 => {
|
||||||
|
func = chash_func((*key).data as *const libc::c_char, (*key).len);
|
||||||
|
indx = func.wrapping_rem((*hash).size);
|
||||||
|
iter = *(*hash).cells.offset(indx as isize);
|
||||||
|
loop {
|
||||||
|
if iter.is_null() {
|
||||||
|
current_block = 17788412896529399552;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (*iter).key.len == (*key).len
|
||||||
|
&& (*iter).func == func
|
||||||
|
&& 0 == memcmp((*iter).key.data, (*key).data, (*key).len as libc::size_t)
|
||||||
|
{
|
||||||
|
/* found, replacing entry */
|
||||||
|
if 0 != (*hash).copyvalue {
|
||||||
|
let mut data: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
data = chash_dup((*value).data, (*value).len);
|
||||||
|
if data.is_null() {
|
||||||
|
current_block = 17701753836843438419;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
free((*iter).value.data);
|
||||||
|
(*iter).value.data = data as *mut libc::c_void;
|
||||||
|
(*iter).value.len = (*value).len
|
||||||
|
} else {
|
||||||
|
if !oldvalue.is_null() {
|
||||||
|
(*oldvalue).data = (*iter).value.data;
|
||||||
|
(*oldvalue).len = (*iter).value.len
|
||||||
|
}
|
||||||
|
(*iter).value.data = (*value).data;
|
||||||
|
(*iter).value.len = (*value).len
|
||||||
|
}
|
||||||
|
if 0 == (*hash).copykey {
|
||||||
|
(*iter).key.data = (*key).data
|
||||||
|
}
|
||||||
|
if !oldvalue.is_null() {
|
||||||
|
(*oldvalue).data = (*value).data;
|
||||||
|
(*oldvalue).len = (*value).len
|
||||||
|
}
|
||||||
|
return 0i32;
|
||||||
|
} else {
|
||||||
|
iter = (*iter).next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
17701753836843438419 => {}
|
||||||
|
_ => {
|
||||||
|
if !oldvalue.is_null() {
|
||||||
|
(*oldvalue).data = 0 as *mut libc::c_void;
|
||||||
|
(*oldvalue).len = 0i32 as libc::c_uint
|
||||||
|
}
|
||||||
|
cell = malloc(::std::mem::size_of::<chashcell>() as libc::size_t)
|
||||||
|
as *mut chashcell;
|
||||||
|
if !cell.is_null() {
|
||||||
|
if 0 != (*hash).copykey {
|
||||||
|
(*cell).key.data =
|
||||||
|
chash_dup((*key).data, (*key).len) as *mut libc::c_void;
|
||||||
|
if (*cell).key.data.is_null() {
|
||||||
|
current_block = 4267898785354516004;
|
||||||
|
} else {
|
||||||
|
current_block = 7226443171521532240;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*cell).key.data = (*key).data;
|
||||||
|
current_block = 7226443171521532240;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
7226443171521532240 => {
|
||||||
|
(*cell).key.len = (*key).len;
|
||||||
|
if 0 != (*hash).copyvalue {
|
||||||
|
(*cell).value.data =
|
||||||
|
chash_dup((*value).data, (*value).len) as *mut libc::c_void;
|
||||||
|
if (*cell).value.data.is_null() {
|
||||||
|
if 0 != (*hash).copykey {
|
||||||
|
free((*cell).key.data);
|
||||||
|
}
|
||||||
|
current_block = 4267898785354516004;
|
||||||
|
} else {
|
||||||
|
current_block = 6717214610478484138;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*cell).value.data = (*value).data;
|
||||||
|
current_block = 6717214610478484138;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
4267898785354516004 => {}
|
||||||
|
_ => {
|
||||||
|
(*cell).value.len = (*value).len;
|
||||||
|
(*cell).func = func;
|
||||||
|
(*cell).next = *(*hash).cells.offset(indx as isize);
|
||||||
|
let ref mut fresh0 = *(*hash).cells.offset(indx as isize);
|
||||||
|
*fresh0 = cell;
|
||||||
|
(*hash).count = (*hash).count.wrapping_add(1);
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(cell as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
unsafe fn chash_dup(mut data: *const libc::c_void, mut len: libc::c_uint) -> *mut libc::c_char {
|
||||||
|
let mut r: *mut libc::c_void = 0 as *mut libc::c_void;
|
||||||
|
r = malloc(len as libc::size_t) as *mut libc::c_char as *mut libc::c_void;
|
||||||
|
if r.is_null() {
|
||||||
|
return 0 as *mut libc::c_char;
|
||||||
|
}
|
||||||
|
memcpy(r, data, len as libc::size_t);
|
||||||
|
return r as *mut libc::c_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn chash_func(mut key: *const libc::c_char, mut len: libc::c_uint) -> libc::c_uint {
|
||||||
|
let mut c: libc::c_uint = 5381i32 as libc::c_uint;
|
||||||
|
let mut k: *const libc::c_char = key;
|
||||||
|
loop {
|
||||||
|
let fresh1 = len;
|
||||||
|
len = len.wrapping_sub(1);
|
||||||
|
if !(0 != fresh1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let fresh2 = k;
|
||||||
|
k = k.offset(1);
|
||||||
|
c = (c << 5i32)
|
||||||
|
.wrapping_add(c)
|
||||||
|
.wrapping_add(*fresh2 as libc::c_uint)
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resizes the hash table to the passed size. */
|
||||||
|
pub unsafe fn chash_resize(mut hash: *mut chash, mut size: libc::c_uint) -> libc::c_int {
|
||||||
|
let mut cells: *mut *mut chashcell = 0 as *mut *mut chashcell;
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
let mut nindx: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut next: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
if (*hash).size == size {
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
cells = calloc(
|
||||||
|
size as libc::size_t,
|
||||||
|
::std::mem::size_of::<*mut chashcell>() as libc::size_t,
|
||||||
|
) as *mut *mut chashcell;
|
||||||
|
if cells.is_null() {
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
indx = 0i32 as libc::c_uint;
|
||||||
|
while indx < (*hash).size {
|
||||||
|
iter = *(*hash).cells.offset(indx as isize);
|
||||||
|
while !iter.is_null() {
|
||||||
|
next = (*iter).next;
|
||||||
|
nindx = (*iter).func.wrapping_rem(size);
|
||||||
|
(*iter).next = *cells.offset(nindx as isize);
|
||||||
|
let ref mut fresh3 = *cells.offset(nindx as isize);
|
||||||
|
*fresh3 = iter;
|
||||||
|
iter = next
|
||||||
|
}
|
||||||
|
indx = indx.wrapping_add(1)
|
||||||
|
}
|
||||||
|
free((*hash).cells as *mut libc::c_void);
|
||||||
|
(*hash).size = size;
|
||||||
|
(*hash).cells = cells;
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieves the data associated to the key if it is found in the hash table.
|
||||||
|
The data pointer and the length will be NULL if not found*/
|
||||||
|
pub unsafe fn chash_get(
|
||||||
|
mut hash: *mut chash,
|
||||||
|
mut key: *mut chashdatum,
|
||||||
|
mut result: *mut chashdatum,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut func: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
func = chash_func((*key).data as *const libc::c_char, (*key).len);
|
||||||
|
iter = *(*hash)
|
||||||
|
.cells
|
||||||
|
.offset(func.wrapping_rem((*hash).size) as isize);
|
||||||
|
while !iter.is_null() {
|
||||||
|
if (*iter).key.len == (*key).len
|
||||||
|
&& (*iter).func == func
|
||||||
|
&& 0 == memcmp((*iter).key.data, (*key).data, (*key).len as libc::size_t)
|
||||||
|
{
|
||||||
|
*result = (*iter).value;
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
iter = (*iter).next
|
||||||
|
}
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
/* Removes the entry associated to this key if it is found in the hash table,
|
||||||
|
and returns its contents if not dupped (otherwise, pointer will be NULL
|
||||||
|
and len TRUE). If entry is not found both pointer and len will be NULL. */
|
||||||
|
pub unsafe fn chash_delete(
|
||||||
|
mut hash: *mut chash,
|
||||||
|
mut key: *mut chashdatum,
|
||||||
|
mut oldvalue: *mut chashdatum,
|
||||||
|
) -> libc::c_int {
|
||||||
|
/* chashdatum result = { NULL, TRUE }; */
|
||||||
|
let mut func: libc::c_uint = 0;
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut old: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
func = chash_func((*key).data as *const libc::c_char, (*key).len);
|
||||||
|
indx = func.wrapping_rem((*hash).size);
|
||||||
|
old = 0 as *mut chashiter;
|
||||||
|
iter = *(*hash).cells.offset(indx as isize);
|
||||||
|
while !iter.is_null() {
|
||||||
|
if (*iter).key.len == (*key).len
|
||||||
|
&& (*iter).func == func
|
||||||
|
&& 0 == memcmp((*iter).key.data, (*key).data, (*key).len as libc::size_t)
|
||||||
|
{
|
||||||
|
if !old.is_null() {
|
||||||
|
(*old).next = (*iter).next
|
||||||
|
} else {
|
||||||
|
let ref mut fresh4 = *(*hash).cells.offset(indx as isize);
|
||||||
|
*fresh4 = (*iter).next
|
||||||
|
}
|
||||||
|
if 0 != (*hash).copykey {
|
||||||
|
free((*iter).key.data);
|
||||||
|
}
|
||||||
|
if 0 != (*hash).copyvalue {
|
||||||
|
free((*iter).value.data);
|
||||||
|
} else if !oldvalue.is_null() {
|
||||||
|
(*oldvalue).data = (*iter).value.data;
|
||||||
|
(*oldvalue).len = (*iter).value.len
|
||||||
|
}
|
||||||
|
free(iter as *mut libc::c_void);
|
||||||
|
(*hash).count = (*hash).count.wrapping_sub(1);
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
old = iter;
|
||||||
|
iter = (*iter).next
|
||||||
|
}
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
/* Returns an iterator to the first non-empty entry of the hash table */
|
||||||
|
pub unsafe fn chash_begin(mut hash: *mut chash) -> *mut chashiter {
|
||||||
|
let mut iter: *mut chashiter = 0 as *mut chashiter;
|
||||||
|
let mut indx: libc::c_uint = 0i32 as libc::c_uint;
|
||||||
|
iter = *(*hash).cells.offset(0isize);
|
||||||
|
while iter.is_null() {
|
||||||
|
indx = indx.wrapping_add(1);
|
||||||
|
if indx >= (*hash).size {
|
||||||
|
return 0 as *mut chashiter;
|
||||||
|
}
|
||||||
|
iter = *(*hash).cells.offset(indx as isize)
|
||||||
|
}
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
/* Returns the next non-empty entry of the hash table */
|
||||||
|
pub unsafe fn chash_next(mut hash: *mut chash, mut iter: *mut chashiter) -> *mut chashiter {
|
||||||
|
let mut indx: libc::c_uint = 0;
|
||||||
|
if iter.is_null() {
|
||||||
|
return 0 as *mut chashiter;
|
||||||
|
}
|
||||||
|
indx = (*iter).func.wrapping_rem((*hash).size);
|
||||||
|
iter = (*iter).next;
|
||||||
|
while iter.is_null() {
|
||||||
|
indx = indx.wrapping_add(1);
|
||||||
|
if indx >= (*hash).size {
|
||||||
|
return 0 as *mut chashiter;
|
||||||
|
}
|
||||||
|
iter = *(*hash).cells.offset(indx as isize)
|
||||||
|
}
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
202
mmime/src/clist.rs
Normal file
202
mmime/src/clist.rs
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
use libc;
|
||||||
|
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct clistcell {
|
||||||
|
pub data: *mut libc::c_void,
|
||||||
|
pub previous: *mut clistcell,
|
||||||
|
pub next: *mut clistcell,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct clist {
|
||||||
|
pub first: *mut clistcell,
|
||||||
|
pub last: *mut clistcell,
|
||||||
|
pub count: libc::c_int,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for clist {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
first: std::ptr::null_mut(),
|
||||||
|
last: std::ptr::null_mut(),
|
||||||
|
count: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for clist {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
let mut l1 = self.first;
|
||||||
|
while !l1.is_null() {
|
||||||
|
let l2 = (*l1).next;
|
||||||
|
free(l1 as *mut libc::c_void);
|
||||||
|
l1 = l2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type clistiter = clistcell;
|
||||||
|
pub struct CListIterator {
|
||||||
|
cur: *mut clistiter,
|
||||||
|
}
|
||||||
|
impl Iterator for CListIterator {
|
||||||
|
type Item = *mut libc::c_void;
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
unsafe {
|
||||||
|
if self.cur.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let data = (*self.cur).data;
|
||||||
|
self.cur = (*self.cur).next;
|
||||||
|
Some(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoIterator for &clist {
|
||||||
|
type Item = *mut libc::c_void;
|
||||||
|
type IntoIter = CListIterator;
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
return CListIterator { cur: self.first };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type clist_func =
|
||||||
|
Option<unsafe extern "C" fn(_: *mut libc::c_void, _: *mut libc::c_void) -> ()>;
|
||||||
|
|
||||||
|
/* Allocate a new pointer list */
|
||||||
|
pub fn clist_new() -> *mut clist {
|
||||||
|
Box::into_raw(Box::new(Default::default()))
|
||||||
|
}
|
||||||
|
/* Destroys a list. Data pointed by data pointers is NOT freed. */
|
||||||
|
pub unsafe fn clist_free(mut lst: *mut clist) {
|
||||||
|
Box::from_raw(lst);
|
||||||
|
}
|
||||||
|
/* Inserts this data pointer after the element pointed by the iterator */
|
||||||
|
pub unsafe fn clist_insert_after(
|
||||||
|
mut lst: *mut clist,
|
||||||
|
mut iter: *mut clistiter,
|
||||||
|
mut data: *mut libc::c_void,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut c: *mut clistcell = 0 as *mut clistcell;
|
||||||
|
c = malloc(::std::mem::size_of::<clistcell>() as libc::size_t) as *mut clistcell;
|
||||||
|
if c.is_null() {
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
(*c).data = data;
|
||||||
|
(*lst).count += 1;
|
||||||
|
if (*lst).first == (*lst).last && (*lst).last.is_null() {
|
||||||
|
(*c).next = 0 as *mut clistcell;
|
||||||
|
(*c).previous = (*c).next;
|
||||||
|
(*lst).last = c;
|
||||||
|
(*lst).first = (*lst).last;
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
if iter.is_null() {
|
||||||
|
(*c).previous = (*lst).last;
|
||||||
|
(*(*c).previous).next = c;
|
||||||
|
(*c).next = 0 as *mut clistcell;
|
||||||
|
(*lst).last = c;
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
(*c).previous = iter;
|
||||||
|
(*c).next = (*iter).next;
|
||||||
|
if !(*c).next.is_null() {
|
||||||
|
(*(*c).next).previous = c
|
||||||
|
} else {
|
||||||
|
(*lst).last = c
|
||||||
|
}
|
||||||
|
(*(*c).previous).next = c;
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
/* Deletes the element pointed by the iterator.
|
||||||
|
Returns an iterator to the next element. */
|
||||||
|
pub unsafe fn clist_delete(mut lst: *mut clist, mut iter: *mut clistiter) -> *mut clistiter {
|
||||||
|
let mut ret: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
if iter.is_null() {
|
||||||
|
return 0 as *mut clistiter;
|
||||||
|
}
|
||||||
|
if !(*iter).previous.is_null() {
|
||||||
|
(*(*iter).previous).next = (*iter).next
|
||||||
|
} else {
|
||||||
|
(*lst).first = (*iter).next
|
||||||
|
}
|
||||||
|
if !(*iter).next.is_null() {
|
||||||
|
(*(*iter).next).previous = (*iter).previous;
|
||||||
|
ret = (*iter).next
|
||||||
|
} else {
|
||||||
|
(*lst).last = (*iter).previous;
|
||||||
|
ret = 0 as *mut clistiter
|
||||||
|
}
|
||||||
|
free(iter as *mut libc::c_void);
|
||||||
|
(*lst).count -= 1;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
pub unsafe fn clist_foreach(
|
||||||
|
mut lst: *mut clist,
|
||||||
|
mut func: clist_func,
|
||||||
|
mut data: *mut libc::c_void,
|
||||||
|
) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*lst).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
func.expect("non-null function pointer")((*cur).data, data);
|
||||||
|
cur = (*cur).next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn clist_nth_data(mut lst: *mut clist, mut indx: libc::c_int) -> *mut libc::c_void {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = internal_clist_nth(lst, indx);
|
||||||
|
if cur.is_null() {
|
||||||
|
return 0 as *mut libc::c_void;
|
||||||
|
}
|
||||||
|
return (*cur).data;
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
unsafe fn internal_clist_nth(mut lst: *mut clist, mut indx: libc::c_int) -> *mut clistiter {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*lst).first;
|
||||||
|
while indx > 0i32 && !cur.is_null() {
|
||||||
|
cur = (*cur).next;
|
||||||
|
indx -= 1
|
||||||
|
}
|
||||||
|
if cur.is_null() {
|
||||||
|
return 0 as *mut clistiter;
|
||||||
|
}
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn clist_nth(mut lst: *mut clist, mut indx: libc::c_int) -> *mut clistiter {
|
||||||
|
return internal_clist_nth(lst, indx);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::ptr;
|
||||||
|
#[test]
|
||||||
|
fn test_clist_iterator() {
|
||||||
|
unsafe {
|
||||||
|
let mut c = clist_new();
|
||||||
|
assert!(!c.is_null());
|
||||||
|
clist_insert_after(c, ptr::null_mut(), clist_nth as _);
|
||||||
|
assert_eq!((*c).count, 1);
|
||||||
|
|
||||||
|
/* Only one iteration */
|
||||||
|
for data in &*c {
|
||||||
|
assert_eq!(data, clist_nth as _);
|
||||||
|
}
|
||||||
|
assert_eq!((*c).count, 1);
|
||||||
|
|
||||||
|
clist_free(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
478
mmime/src/lib.rs
Normal file
478
mmime/src/lib.rs
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
#![deny(clippy::correctness)]
|
||||||
|
// TODO: make all of these errors, such that clippy actually passes.
|
||||||
|
#![warn(clippy::all, clippy::perf, clippy::not_unsafe_ptr_arg_deref)]
|
||||||
|
// This is nice, but for now just annoying.
|
||||||
|
#![allow(clippy::unreadable_literal)]
|
||||||
|
#![feature(ptr_wrapping_offset_from)]
|
||||||
|
#![allow(unused_attributes)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![allow(mutable_transmutes)]
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
#![allow(non_upper_case_globals)]
|
||||||
|
#![allow(unused_assignments)]
|
||||||
|
#![allow(unused_mut)]
|
||||||
|
#![allow(unused_must_use)]
|
||||||
|
#![feature(extern_types)]
|
||||||
|
#![feature(const_raw_ptr_to_usize_cast)]
|
||||||
|
|
||||||
|
pub mod charconv;
|
||||||
|
pub mod chash;
|
||||||
|
pub mod clist;
|
||||||
|
pub mod mailimf;
|
||||||
|
pub mod mailimf_types;
|
||||||
|
pub mod mailimf_types_helper;
|
||||||
|
pub mod mailimf_write_generic;
|
||||||
|
pub mod mailmime;
|
||||||
|
pub mod mailmime_content;
|
||||||
|
pub mod mailmime_decode;
|
||||||
|
pub mod mailmime_disposition;
|
||||||
|
pub mod mailmime_types;
|
||||||
|
pub mod mailmime_types_helper;
|
||||||
|
pub mod mailmime_write_generic;
|
||||||
|
pub mod mailmime_write_mem;
|
||||||
|
pub mod mmapstring;
|
||||||
|
pub mod other;
|
||||||
|
|
||||||
|
pub use self::charconv::*;
|
||||||
|
pub use self::chash::*;
|
||||||
|
pub use self::clist::*;
|
||||||
|
pub use self::mailimf::*;
|
||||||
|
pub use self::mailimf_types::*;
|
||||||
|
pub use self::mailimf_types_helper::*;
|
||||||
|
pub use self::mailimf_write_generic::*;
|
||||||
|
pub use self::mailmime::*;
|
||||||
|
pub use self::mailmime_content::*;
|
||||||
|
pub use self::mailmime_decode::*;
|
||||||
|
pub use self::mailmime_disposition::*;
|
||||||
|
pub use self::mailmime_types::*;
|
||||||
|
pub use self::mailmime_types_helper::*;
|
||||||
|
pub use self::mailmime_write_generic::*;
|
||||||
|
pub use self::mailmime_write_mem::*;
|
||||||
|
pub use self::mmapstring::*;
|
||||||
|
pub use self::other::*;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::mailmime_types::{mailmime, mailmime_content, mailmime_disposition};
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mailmime_parse_test() {
|
||||||
|
unsafe {
|
||||||
|
let data = "MIME-Version: 1.0\
|
||||||
|
Content-Type: multipart/mixed; boundary=frontier\
|
||||||
|
\
|
||||||
|
This is a message with multiple parts in MIME format.\
|
||||||
|
--frontier\
|
||||||
|
Content-Type: text/plain\
|
||||||
|
\
|
||||||
|
This is the body of the message.\
|
||||||
|
--frontier\
|
||||||
|
Content-Type: application/octet-stream\
|
||||||
|
Content-Transfer-Encoding: base64\
|
||||||
|
\
|
||||||
|
PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\
|
||||||
|
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==\
|
||||||
|
--frontier--";
|
||||||
|
let c_data = std::ffi::CString::new(data).unwrap();
|
||||||
|
|
||||||
|
let mut current_index = 0;
|
||||||
|
let mut mime = std::ptr::null_mut();
|
||||||
|
let res = crate::mailmime_content::mailmime_parse(
|
||||||
|
c_data.as_ptr(),
|
||||||
|
data.len() as usize,
|
||||||
|
&mut current_index,
|
||||||
|
&mut mime,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(res, MAIL_NO_ERROR as libc::c_int);
|
||||||
|
assert!(!mime.is_null());
|
||||||
|
|
||||||
|
display_mime(mime);
|
||||||
|
|
||||||
|
mailmime_types::mailmime_free(mime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn display_mime(mut mime: *mut mailmime) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
println!("{}", (*mime).mm_type);
|
||||||
|
|
||||||
|
match (*mime).mm_type {
|
||||||
|
1 => {
|
||||||
|
println!("single part");
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
println!("multipart");
|
||||||
|
}
|
||||||
|
3 => println!("message"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if !(*mime).mm_mime_fields.is_null() {
|
||||||
|
if !(*(*(*mime).mm_mime_fields).fld_list).first.is_null() {
|
||||||
|
print!("MIME headers begin");
|
||||||
|
display_mime_fields((*mime).mm_mime_fields);
|
||||||
|
println!("MIME headers end");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display_mime_content((*mime).mm_content_type);
|
||||||
|
match (*mime).mm_type {
|
||||||
|
1 => {
|
||||||
|
display_mime_data((*mime).mm_data.mm_single);
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
cur = (*(*mime).mm_data.mm_multipart.mm_mp_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
display_mime(
|
||||||
|
(if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailmime,
|
||||||
|
);
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
if !(*mime).mm_data.mm_message.mm_fields.is_null() {
|
||||||
|
if !(*(*(*mime).mm_data.mm_message.mm_fields).fld_list)
|
||||||
|
.first
|
||||||
|
.is_null()
|
||||||
|
{
|
||||||
|
println!("headers begin");
|
||||||
|
display_fields((*mime).mm_data.mm_message.mm_fields);
|
||||||
|
println!("headers end");
|
||||||
|
}
|
||||||
|
if !(*mime).mm_data.mm_message.mm_msg_mime.is_null() {
|
||||||
|
display_mime((*mime).mm_data.mm_message.mm_msg_mime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn display_mime_content(mut content_type: *mut mailmime_content) {
|
||||||
|
print!("type: ");
|
||||||
|
display_mime_type((*content_type).ct_type);
|
||||||
|
println!(
|
||||||
|
"/{}",
|
||||||
|
CStr::from_ptr((*content_type).ct_subtype).to_str().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_type(mut type_0: *mut mailmime_type) {
|
||||||
|
match (*type_0).tp_type {
|
||||||
|
1 => {
|
||||||
|
display_mime_discrete_type((*type_0).tp_data.tp_discrete_type);
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
display_mime_composite_type((*type_0).tp_data.tp_composite_type);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_composite_type(mut ct: *mut mailmime_composite_type) {
|
||||||
|
match (*ct).ct_type {
|
||||||
|
1 => {
|
||||||
|
print!("message");
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
print!("multipart");
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
print!("{}", CStr::from_ptr((*ct).ct_token).to_str().unwrap());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_discrete_type(mut discrete_type: *mut mailmime_discrete_type) {
|
||||||
|
match (*discrete_type).dt_type {
|
||||||
|
1 => {
|
||||||
|
print!("text");
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
print!("image");
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
print!("audio");
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
print!("video");
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
print!("application");
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
print!("{}", (*discrete_type).dt_extension as u8 as char);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_data(mut data: *mut mailmime_data) {
|
||||||
|
match (*data).dt_type {
|
||||||
|
0 => {
|
||||||
|
println!(
|
||||||
|
"data : {} bytes",
|
||||||
|
(*data).dt_data.dt_text.dt_length as libc::c_uint,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
println!(
|
||||||
|
"data (file) : {}",
|
||||||
|
CStr::from_ptr((*data).dt_data.dt_filename)
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_dsp_parm(mut param: *mut mailmime_disposition_parm) {
|
||||||
|
match (*param).pa_type {
|
||||||
|
0 => {
|
||||||
|
println!(
|
||||||
|
"filename: {}",
|
||||||
|
CStr::from_ptr((*param).pa_data.pa_filename)
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_disposition(mut disposition: *mut mailmime_disposition) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*(*disposition).dsp_parms).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut param: *mut mailmime_disposition_parm = 0 as *mut mailmime_disposition_parm;
|
||||||
|
param = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailmime_disposition_parm;
|
||||||
|
display_mime_dsp_parm(param);
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_field(mut field: *mut mailmime_field) {
|
||||||
|
match (*field).fld_type {
|
||||||
|
1 => {
|
||||||
|
print!("content-type: ");
|
||||||
|
display_mime_content((*field).fld_data.fld_content);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
display_mime_disposition((*field).fld_data.fld_disposition);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_mime_fields(mut fields: *mut mailmime_fields) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*(*fields).fld_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut field: *mut mailmime_field = 0 as *mut mailmime_field;
|
||||||
|
field = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailmime_field;
|
||||||
|
display_mime_field(field);
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe fn display_date_time(mut d: *mut mailimf_date_time) {
|
||||||
|
print!(
|
||||||
|
"{:02}/{:02}/{:02} {:02}:{:02}:{:02} +{:04}",
|
||||||
|
(*d).dt_day,
|
||||||
|
(*d).dt_month,
|
||||||
|
(*d).dt_year,
|
||||||
|
(*d).dt_hour,
|
||||||
|
(*d).dt_min,
|
||||||
|
(*d).dt_sec,
|
||||||
|
(*d).dt_zone,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
unsafe fn display_orig_date(mut orig_date: *mut mailimf_orig_date) {
|
||||||
|
display_date_time((*orig_date).dt_date_time);
|
||||||
|
}
|
||||||
|
unsafe fn display_mailbox(mut mb: *mut mailimf_mailbox) {
|
||||||
|
if !(*mb).mb_display_name.is_null() {
|
||||||
|
print!(
|
||||||
|
"{}",
|
||||||
|
CStr::from_ptr((*mb).mb_display_name).to_str().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
print!("<{}>", CStr::from_ptr((*mb).mb_addr_spec).to_str().unwrap());
|
||||||
|
}
|
||||||
|
unsafe fn display_mailbox_list(mut mb_list: *mut mailimf_mailbox_list) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*(*mb_list).mb_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut mb: *mut mailimf_mailbox = 0 as *mut mailimf_mailbox;
|
||||||
|
mb = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailimf_mailbox;
|
||||||
|
display_mailbox(mb);
|
||||||
|
if !if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
.is_null()
|
||||||
|
{
|
||||||
|
print!(", ");
|
||||||
|
}
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe fn display_group(mut group: *mut mailimf_group) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
print!(
|
||||||
|
"{}: ",
|
||||||
|
CStr::from_ptr((*group).grp_display_name).to_str().unwrap()
|
||||||
|
);
|
||||||
|
cur = (*(*(*group).grp_mb_list).mb_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut mb: *mut mailimf_mailbox = 0 as *mut mailimf_mailbox;
|
||||||
|
mb = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailimf_mailbox;
|
||||||
|
display_mailbox(mb);
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print!("; ");
|
||||||
|
}
|
||||||
|
unsafe fn display_address(mut a: *mut mailimf_address) {
|
||||||
|
match (*a).ad_type {
|
||||||
|
2 => {
|
||||||
|
display_group((*a).ad_data.ad_group);
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
display_mailbox((*a).ad_data.ad_mailbox);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_address_list(mut addr_list: *mut mailimf_address_list) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*(*addr_list).ad_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut addr: *mut mailimf_address = 0 as *mut mailimf_address;
|
||||||
|
addr = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailimf_address;
|
||||||
|
display_address(addr);
|
||||||
|
if !if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
.is_null()
|
||||||
|
{
|
||||||
|
print!(", ");
|
||||||
|
}
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe fn display_from(mut from: *mut mailimf_from) {
|
||||||
|
display_mailbox_list((*from).frm_mb_list);
|
||||||
|
}
|
||||||
|
unsafe fn display_to(mut to: *mut mailimf_to) {
|
||||||
|
display_address_list((*to).to_addr_list);
|
||||||
|
}
|
||||||
|
unsafe fn display_cc(mut cc: *mut mailimf_cc) {
|
||||||
|
display_address_list((*cc).cc_addr_list);
|
||||||
|
}
|
||||||
|
unsafe fn display_subject(mut subject: *mut mailimf_subject) {
|
||||||
|
print!("{}", CStr::from_ptr((*subject).sbj_value).to_str().unwrap());
|
||||||
|
}
|
||||||
|
unsafe fn display_field(mut field: *mut mailimf_field) {
|
||||||
|
match (*field).fld_type {
|
||||||
|
9 => {
|
||||||
|
print!("Date: ");
|
||||||
|
display_orig_date((*field).fld_data.fld_orig_date);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
10 => {
|
||||||
|
print!("From: ");
|
||||||
|
display_from((*field).fld_data.fld_from);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
13 => {
|
||||||
|
print!("To: ");
|
||||||
|
display_to((*field).fld_data.fld_to);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
14 => {
|
||||||
|
print!("Cc: ");
|
||||||
|
display_cc((*field).fld_data.fld_cc);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
19 => {
|
||||||
|
print!("Subject: ");
|
||||||
|
display_subject((*field).fld_data.fld_subject);
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
16 => {
|
||||||
|
println!(
|
||||||
|
"Message-ID: {}",
|
||||||
|
CStr::from_ptr((*(*field).fld_data.fld_message_id).mid_value)
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
unsafe fn display_fields(mut fields: *mut mailimf_fields) {
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
cur = (*(*fields).fld_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut f: *mut mailimf_field = 0 as *mut mailimf_field;
|
||||||
|
f = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailimf_field;
|
||||||
|
display_field(f);
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5918
mmime/src/mailimf.rs
Normal file
5918
mmime/src/mailimf.rs
Normal file
File diff suppressed because it is too large
Load Diff
1182
mmime/src/mailimf_types.rs
Normal file
1182
mmime/src/mailimf_types.rs
Normal file
File diff suppressed because it is too large
Load Diff
89
mmime/src/mailimf_types_helper.rs
Normal file
89
mmime/src/mailimf_types_helper.rs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
use crate::clist::*;
|
||||||
|
use crate::mailimf_types::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
this function creates a new mailimf_fields structure with no fields
|
||||||
|
*/
|
||||||
|
pub unsafe fn mailimf_fields_new_empty() -> *mut mailimf_fields {
|
||||||
|
let mut list: *mut clist = 0 as *mut clist;
|
||||||
|
let mut fields_list: *mut mailimf_fields = 0 as *mut mailimf_fields;
|
||||||
|
list = clist_new();
|
||||||
|
if list.is_null() {
|
||||||
|
return 0 as *mut mailimf_fields;
|
||||||
|
}
|
||||||
|
fields_list = mailimf_fields_new(list);
|
||||||
|
if fields_list.is_null() {
|
||||||
|
return 0 as *mut mailimf_fields;
|
||||||
|
}
|
||||||
|
return fields_list;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
this function adds a field to the mailimf_fields structure
|
||||||
|
|
||||||
|
@return MAILIMF_NO_ERROR will be returned on success,
|
||||||
|
other code will be returned otherwise
|
||||||
|
*/
|
||||||
|
pub unsafe fn mailimf_fields_add(
|
||||||
|
mut fields: *mut mailimf_fields,
|
||||||
|
mut field: *mut mailimf_field,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
r = clist_insert_after(
|
||||||
|
(*fields).fld_list,
|
||||||
|
(*(*fields).fld_list).last,
|
||||||
|
field as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
if r < 0i32 {
|
||||||
|
return MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
}
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
mailimf_field_new_custom creates a new field of type optional
|
||||||
|
|
||||||
|
@param name should be allocated with malloc()
|
||||||
|
@param value should be allocated with malloc()
|
||||||
|
*/
|
||||||
|
pub unsafe fn mailimf_field_new_custom(
|
||||||
|
mut name: *mut libc::c_char,
|
||||||
|
mut value: *mut libc::c_char,
|
||||||
|
) -> *mut mailimf_field {
|
||||||
|
let mut opt_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field;
|
||||||
|
let mut field: *mut mailimf_field = 0 as *mut mailimf_field;
|
||||||
|
opt_field = mailimf_optional_field_new(name, value);
|
||||||
|
if !opt_field.is_null() {
|
||||||
|
field = mailimf_field_new(
|
||||||
|
MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int,
|
||||||
|
0 as *mut mailimf_return,
|
||||||
|
0 as *mut mailimf_orig_date,
|
||||||
|
0 as *mut mailimf_from,
|
||||||
|
0 as *mut mailimf_sender,
|
||||||
|
0 as *mut mailimf_to,
|
||||||
|
0 as *mut mailimf_cc,
|
||||||
|
0 as *mut mailimf_bcc,
|
||||||
|
0 as *mut mailimf_message_id,
|
||||||
|
0 as *mut mailimf_orig_date,
|
||||||
|
0 as *mut mailimf_from,
|
||||||
|
0 as *mut mailimf_sender,
|
||||||
|
0 as *mut mailimf_reply_to,
|
||||||
|
0 as *mut mailimf_to,
|
||||||
|
0 as *mut mailimf_cc,
|
||||||
|
0 as *mut mailimf_bcc,
|
||||||
|
0 as *mut mailimf_message_id,
|
||||||
|
0 as *mut mailimf_in_reply_to,
|
||||||
|
0 as *mut mailimf_references,
|
||||||
|
0 as *mut mailimf_subject,
|
||||||
|
0 as *mut mailimf_comments,
|
||||||
|
0 as *mut mailimf_keywords,
|
||||||
|
opt_field,
|
||||||
|
);
|
||||||
|
if field.is_null() {
|
||||||
|
mailimf_optional_field_free(opt_field);
|
||||||
|
} else {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0 as *mut mailimf_field;
|
||||||
|
}
|
||||||
2025
mmime/src/mailimf_write_generic.rs
Normal file
2025
mmime/src/mailimf_write_generic.rs
Normal file
File diff suppressed because it is too large
Load Diff
1137
mmime/src/mailmime.rs
Normal file
1137
mmime/src/mailmime.rs
Normal file
File diff suppressed because it is too large
Load Diff
2357
mmime/src/mailmime_content.rs
Normal file
2357
mmime/src/mailmime_content.rs
Normal file
File diff suppressed because it is too large
Load Diff
863
mmime/src/mailmime_decode.rs
Normal file
863
mmime/src/mailmime_decode.rs
Normal file
@@ -0,0 +1,863 @@
|
|||||||
|
use libc;
|
||||||
|
use libc::toupper;
|
||||||
|
|
||||||
|
use crate::charconv::*;
|
||||||
|
use crate::mailimf::*;
|
||||||
|
use crate::mailmime_content::*;
|
||||||
|
use crate::mailmime_types::*;
|
||||||
|
use crate::mmapstring::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
pub const MAIL_CHARCONV_ERROR_CONV: libc::c_uint = 3;
|
||||||
|
pub const MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: libc::c_uint = 1;
|
||||||
|
pub const MAIL_CHARCONV_ERROR_MEMORY: libc::c_uint = 2;
|
||||||
|
pub const TYPE_WORD: libc::c_uint = 1;
|
||||||
|
pub const TYPE_ENCODED_WORD: libc::c_uint = 2;
|
||||||
|
pub const MAILMIME_ENCODING_Q: libc::c_uint = 1;
|
||||||
|
pub const MAILMIME_ENCODING_B: libc::c_uint = 0;
|
||||||
|
pub const TYPE_ERROR: libc::c_uint = 0;
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoded_phrase_parse(
|
||||||
|
mut default_fromcode: *const libc::c_char,
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut tocode: *const libc::c_char,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut current_block: u64;
|
||||||
|
let mut gphrase: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
let mut word: *mut mailmime_encoded_word = 0 as *mut mailmime_encoded_word;
|
||||||
|
let mut first: libc::c_int = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
let mut str: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut wordutf8: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut type_0: libc::c_int = 0;
|
||||||
|
let mut missing_closing_quote: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
gphrase = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||||
|
if gphrase.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int
|
||||||
|
} else {
|
||||||
|
first = 1i32;
|
||||||
|
type_0 = TYPE_ERROR as libc::c_int;
|
||||||
|
loop {
|
||||||
|
let mut has_fwd: libc::c_int = 0;
|
||||||
|
word = 0 as *mut mailmime_encoded_word;
|
||||||
|
r = mailmime_encoded_word_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut word,
|
||||||
|
&mut has_fwd,
|
||||||
|
&mut missing_closing_quote,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
if 0 == first && 0 != has_fwd {
|
||||||
|
if type_0 != TYPE_ENCODED_WORD as libc::c_int {
|
||||||
|
if mmap_string_append_c(gphrase, ' ' as i32 as libc::c_char).is_null() {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type_0 = TYPE_ENCODED_WORD as libc::c_int;
|
||||||
|
wordutf8 = 0 as *mut libc::c_char;
|
||||||
|
r = charconv(
|
||||||
|
tocode,
|
||||||
|
(*word).wd_charset,
|
||||||
|
(*word).wd_text,
|
||||||
|
strlen((*word).wd_text),
|
||||||
|
&mut wordutf8,
|
||||||
|
);
|
||||||
|
match r {
|
||||||
|
2 => {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
r = charconv(
|
||||||
|
tocode,
|
||||||
|
b"iso-8859-1\x00" as *const u8 as *const libc::c_char,
|
||||||
|
(*word).wd_text,
|
||||||
|
strlen((*word).wd_text),
|
||||||
|
&mut wordutf8,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
res = MAILIMF_ERROR_PARSE as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
match r {
|
||||||
|
2 => {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
res = MAILIMF_ERROR_PARSE as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
if !wordutf8.is_null() {
|
||||||
|
if mmap_string_append(gphrase, wordutf8).is_null() {
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
free(wordutf8 as *mut libc::c_void);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
free(wordutf8 as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mailmime_encoded_word_free(word);
|
||||||
|
first = 0i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !(r == MAILIMF_ERROR_PARSE as libc::c_int) {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if !(r == MAILIMF_ERROR_PARSE as libc::c_int) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut raw_word: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
raw_word = 0 as *mut libc::c_char;
|
||||||
|
r = mailmime_non_encoded_word_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut raw_word,
|
||||||
|
&mut has_fwd,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
if 0 == first && 0 != has_fwd {
|
||||||
|
if mmap_string_append_c(gphrase, ' ' as i32 as libc::c_char).is_null() {
|
||||||
|
free(raw_word as *mut libc::c_void);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type_0 = TYPE_WORD as libc::c_int;
|
||||||
|
wordutf8 = 0 as *mut libc::c_char;
|
||||||
|
r = charconv(
|
||||||
|
tocode,
|
||||||
|
default_fromcode,
|
||||||
|
raw_word,
|
||||||
|
strlen(raw_word),
|
||||||
|
&mut wordutf8,
|
||||||
|
);
|
||||||
|
match r {
|
||||||
|
2 => {
|
||||||
|
free(raw_word as *mut libc::c_void);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
1 | 3 => {
|
||||||
|
free(raw_word as *mut libc::c_void);
|
||||||
|
res = MAILIMF_ERROR_PARSE as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
if mmap_string_append(gphrase, wordutf8).is_null() {
|
||||||
|
free(wordutf8 as *mut libc::c_void);
|
||||||
|
free(raw_word as *mut libc::c_void);
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
free(wordutf8 as *mut libc::c_void);
|
||||||
|
free(raw_word as *mut libc::c_void);
|
||||||
|
first = 0i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
r = mailimf_fws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 5005389895767293342;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if mmap_string_append_c(gphrase, ' ' as i32 as libc::c_char).is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
first = 0i32;
|
||||||
|
current_block = 5005389895767293342;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res = r;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
5005389895767293342 => {
|
||||||
|
if 0 != first {
|
||||||
|
if cur_token != length {
|
||||||
|
res = MAILIMF_ERROR_PARSE as libc::c_int;
|
||||||
|
current_block = 13246848547199022064;
|
||||||
|
} else {
|
||||||
|
current_block = 7072655752890836508;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_block = 7072655752890836508;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
13246848547199022064 => {}
|
||||||
|
_ => {
|
||||||
|
str = strdup((*gphrase).str_0);
|
||||||
|
if str.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int
|
||||||
|
} else {
|
||||||
|
mmap_string_free(gphrase);
|
||||||
|
*result = str;
|
||||||
|
*indx = cur_token;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
mmap_string_free(gphrase);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_non_encoded_word_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
mut p_has_fwd: *mut libc::c_int,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut end: libc::c_int = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
let mut text: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut begin: size_t = 0;
|
||||||
|
let mut state: libc::c_int = 0;
|
||||||
|
let mut has_fwd: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
has_fwd = 0i32;
|
||||||
|
r = mailimf_fws_parse(message, length, &mut cur_token);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
has_fwd = 1i32
|
||||||
|
}
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
begin = cur_token;
|
||||||
|
state = 0i32;
|
||||||
|
end = 0i32;
|
||||||
|
while !(cur_token >= length) {
|
||||||
|
let mut current_block_17: u64;
|
||||||
|
match *message.offset(cur_token as isize) as libc::c_int {
|
||||||
|
32 | 9 | 13 | 10 => {
|
||||||
|
state = 0i32;
|
||||||
|
end = 1i32;
|
||||||
|
current_block_17 = 16924917904204750491;
|
||||||
|
}
|
||||||
|
61 => {
|
||||||
|
state = 1i32;
|
||||||
|
current_block_17 = 16924917904204750491;
|
||||||
|
}
|
||||||
|
63 => {
|
||||||
|
if state == 1i32 {
|
||||||
|
cur_token = cur_token.wrapping_sub(1);
|
||||||
|
end = 1i32
|
||||||
|
}
|
||||||
|
current_block_17 = 10192508258555769664;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
current_block_17 = 10192508258555769664;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block_17 {
|
||||||
|
10192508258555769664 => state = 0i32,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if 0 != end {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cur_token = cur_token.wrapping_add(1)
|
||||||
|
}
|
||||||
|
if cur_token.wrapping_sub(begin) == 0i32 as libc::size_t {
|
||||||
|
res = MAILIMF_ERROR_PARSE as libc::c_int
|
||||||
|
} else {
|
||||||
|
text = malloc(
|
||||||
|
cur_token
|
||||||
|
.wrapping_sub(begin)
|
||||||
|
.wrapping_add(1i32 as libc::size_t),
|
||||||
|
) as *mut libc::c_char;
|
||||||
|
if text.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int
|
||||||
|
} else {
|
||||||
|
memcpy(
|
||||||
|
text as *mut libc::c_void,
|
||||||
|
message.offset(begin as isize) as *const libc::c_void,
|
||||||
|
cur_token.wrapping_sub(begin),
|
||||||
|
);
|
||||||
|
*text.offset(cur_token.wrapping_sub(begin) as isize) =
|
||||||
|
'\u{0}' as i32 as libc::c_char;
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = text;
|
||||||
|
*p_has_fwd = has_fwd;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoded_word_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut mailmime_encoded_word,
|
||||||
|
mut p_has_fwd: *mut libc::c_int,
|
||||||
|
mut p_missing_closing_quote: *mut libc::c_int,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut current_block: u64;
|
||||||
|
/*
|
||||||
|
Parse the following, when a unicode character encoding is split.
|
||||||
|
=?UTF-8?B?4Lij4Liw4LmA4Lia4Li04LiU4LiE4Lin4Liy4Lih4Lih4Lix4LiZ4Liq4LmM?=
|
||||||
|
=?UTF-8?B?4LmA4LiV4LmH4Lih4Lie4Li04LiB4Lix4LiUIFRSQU5TRk9STUVSUyA0IOC4?=
|
||||||
|
=?UTF-8?B?oeC4seC4meC4quC5jOC4hOC4o+C4muC4l+C4uOC4geC4o+C4sOC4muC4miDg?=
|
||||||
|
=?UTF-8?B?uJfguLXguYjguYDguJTguLXguKLguKfguYPguJnguYDguKHguLfguK3guIfg?=
|
||||||
|
=?UTF-8?B?uYTguJfguKI=?=
|
||||||
|
Expected result:
|
||||||
|
ระเบิดความมันส์เต็มพิกัด TRANSFORMERS 4 มันส์ครบทุกระบบ ที่เดียวในเมืองไทย
|
||||||
|
libetpan result:
|
||||||
|
ระเบิดความมันส์เต็มพิกัด TRANSFORMERS 4 ?ันส์ครบทุกระบบ ??ี่เดียวในเมือง??ทย
|
||||||
|
|
||||||
|
See https://github.com/dinhviethoa/libetpan/pull/211
|
||||||
|
*/
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut charset: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut encoding: libc::c_int = 0;
|
||||||
|
let mut body: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut old_body_len: size_t = 0;
|
||||||
|
let mut text: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut end_encoding: size_t = 0;
|
||||||
|
let mut lookfwd_cur_token: size_t = 0;
|
||||||
|
let mut lookfwd_charset: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut lookfwd_encoding: libc::c_int = 0;
|
||||||
|
let mut copy_len: size_t = 0;
|
||||||
|
let mut decoded_token: size_t = 0;
|
||||||
|
let mut decoded: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut decoded_len: size_t = 0;
|
||||||
|
let mut ew: *mut mailmime_encoded_word = 0 as *mut mailmime_encoded_word;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
let mut opening_quote: libc::c_int = 0;
|
||||||
|
let mut end: libc::c_int = 0;
|
||||||
|
let mut has_fwd: libc::c_int = 0;
|
||||||
|
let mut missing_closing_quote: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
text = 0 as *mut libc::c_char;
|
||||||
|
lookfwd_charset = 0 as *mut libc::c_char;
|
||||||
|
missing_closing_quote = 0i32;
|
||||||
|
has_fwd = 0i32;
|
||||||
|
r = mailimf_fws_parse(message, length, &mut cur_token);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
has_fwd = 1i32
|
||||||
|
}
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
opening_quote = 0i32;
|
||||||
|
r = mailimf_char_parse(message, length, &mut cur_token, '\"' as i32 as libc::c_char);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
opening_quote = 1i32;
|
||||||
|
current_block = 17788412896529399552;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 17788412896529399552;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 7995813543095296079;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
7995813543095296079 => {}
|
||||||
|
_ => {
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"=?\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"=?\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
r = mailmime_charset_parse(message, length, &mut cur_token, &mut charset);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
r = mailimf_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
'?' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
r = mailmime_encoding_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut encoding,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
r = mailimf_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
'?' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
lookfwd_cur_token = cur_token;
|
||||||
|
body = 0 as *mut libc::c_char;
|
||||||
|
old_body_len = 0i32 as size_t;
|
||||||
|
loop {
|
||||||
|
let mut has_base64_padding: libc::c_int = 0;
|
||||||
|
end = 0i32;
|
||||||
|
has_base64_padding = 0i32;
|
||||||
|
end_encoding = cur_token;
|
||||||
|
while !(end_encoding >= length) {
|
||||||
|
if end_encoding.wrapping_add(1i32 as libc::size_t)
|
||||||
|
< length
|
||||||
|
{
|
||||||
|
if *message.offset(end_encoding as isize)
|
||||||
|
as libc::c_int
|
||||||
|
== '?' as i32
|
||||||
|
&& *message.offset(
|
||||||
|
end_encoding
|
||||||
|
.wrapping_add(1i32 as libc::size_t)
|
||||||
|
as isize,
|
||||||
|
)
|
||||||
|
as libc::c_int
|
||||||
|
== '=' as i32
|
||||||
|
{
|
||||||
|
end = 1i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if 0 != end {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
end_encoding = end_encoding.wrapping_add(1)
|
||||||
|
}
|
||||||
|
copy_len = end_encoding.wrapping_sub(lookfwd_cur_token);
|
||||||
|
if copy_len > 0i32 as libc::size_t {
|
||||||
|
if encoding == MAILMIME_ENCODING_B as libc::c_int {
|
||||||
|
if end_encoding >= 1i32 as libc::size_t {
|
||||||
|
if *message.offset(
|
||||||
|
end_encoding
|
||||||
|
.wrapping_sub(1i32 as libc::size_t)
|
||||||
|
as isize,
|
||||||
|
)
|
||||||
|
as libc::c_int
|
||||||
|
== '=' as i32
|
||||||
|
{
|
||||||
|
has_base64_padding = 1i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body = realloc(
|
||||||
|
body as *mut libc::c_void,
|
||||||
|
old_body_len
|
||||||
|
.wrapping_add(copy_len)
|
||||||
|
.wrapping_add(1i32 as libc::size_t),
|
||||||
|
)
|
||||||
|
as *mut libc::c_char;
|
||||||
|
if body.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13900684162107791171;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
memcpy(
|
||||||
|
body.offset(old_body_len as isize)
|
||||||
|
as *mut libc::c_void,
|
||||||
|
&*message.offset(cur_token as isize)
|
||||||
|
as *const libc::c_char
|
||||||
|
as *const libc::c_void,
|
||||||
|
copy_len,
|
||||||
|
);
|
||||||
|
*body
|
||||||
|
.offset(old_body_len.wrapping_add(copy_len)
|
||||||
|
as isize) = '\u{0}' as i32 as libc::c_char;
|
||||||
|
old_body_len = (old_body_len as libc::size_t)
|
||||||
|
.wrapping_add(copy_len)
|
||||||
|
as size_t
|
||||||
|
as size_t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur_token = end_encoding;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"?=\x00" as *const u8 as *const libc::c_char
|
||||||
|
as *mut libc::c_char,
|
||||||
|
strlen(b"?=\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if 0 != has_base64_padding {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lookfwd_cur_token = cur_token;
|
||||||
|
r = mailimf_fws_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int
|
||||||
|
&& r != MAILIMF_ERROR_PARSE as libc::c_int
|
||||||
|
{
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
b"=?\x00" as *const u8 as *const libc::c_char
|
||||||
|
as *mut libc::c_char,
|
||||||
|
strlen(b"=?\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = mailmime_charset_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
&mut lookfwd_charset,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = mailimf_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
'?' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = mailmime_encoding_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
&mut lookfwd_encoding,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = mailimf_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut lookfwd_cur_token,
|
||||||
|
'?' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if strcasecmp(charset, lookfwd_charset) == 0i32
|
||||||
|
&& encoding == lookfwd_encoding
|
||||||
|
{
|
||||||
|
cur_token = lookfwd_cur_token;
|
||||||
|
mailmime_charset_free(lookfwd_charset);
|
||||||
|
lookfwd_charset = 0 as *mut libc::c_char
|
||||||
|
} else {
|
||||||
|
/* the next charset is not matched with the current one,
|
||||||
|
therefore exit the loop to decode the body appended so far */
|
||||||
|
current_block = 2652804691515851435;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
2652804691515851435 => {
|
||||||
|
if !lookfwd_charset.is_null() {
|
||||||
|
mailmime_charset_free(lookfwd_charset);
|
||||||
|
lookfwd_charset = 0 as *mut libc::c_char
|
||||||
|
}
|
||||||
|
if body.is_null() {
|
||||||
|
body = strdup(
|
||||||
|
b"\x00" as *const u8 as *const libc::c_char,
|
||||||
|
);
|
||||||
|
if body.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 13900684162107791171;
|
||||||
|
} else {
|
||||||
|
current_block = 16778110326724371720;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_block = 16778110326724371720;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
13900684162107791171 => {}
|
||||||
|
_ => {
|
||||||
|
decoded_token = 0i32 as size_t;
|
||||||
|
decoded_len = 0i32 as size_t;
|
||||||
|
decoded = 0 as *mut libc::c_char;
|
||||||
|
match encoding {
|
||||||
|
0 => {
|
||||||
|
r = mailmime_base64_body_parse(
|
||||||
|
body,
|
||||||
|
strlen(body),
|
||||||
|
&mut decoded_token,
|
||||||
|
&mut decoded,
|
||||||
|
&mut decoded_len,
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int
|
||||||
|
{
|
||||||
|
res = r;
|
||||||
|
current_block =
|
||||||
|
13900684162107791171;
|
||||||
|
} else {
|
||||||
|
current_block = 7337917895049117968;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
r =
|
||||||
|
mailmime_quoted_printable_body_parse(body,
|
||||||
|
strlen(body),
|
||||||
|
&mut decoded_token,
|
||||||
|
&mut decoded,
|
||||||
|
&mut decoded_len,
|
||||||
|
1i32);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int
|
||||||
|
{
|
||||||
|
res = r;
|
||||||
|
current_block =
|
||||||
|
13900684162107791171;
|
||||||
|
} else {
|
||||||
|
current_block = 7337917895049117968;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
current_block = 7337917895049117968;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
13900684162107791171 => {}
|
||||||
|
_ => {
|
||||||
|
text =
|
||||||
|
malloc(decoded_len.wrapping_add(
|
||||||
|
1i32 as libc::size_t,
|
||||||
|
))
|
||||||
|
as *mut libc::c_char;
|
||||||
|
if text.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY
|
||||||
|
as libc::c_int
|
||||||
|
} else {
|
||||||
|
if decoded_len
|
||||||
|
> 0i32 as libc::size_t
|
||||||
|
{
|
||||||
|
memcpy(
|
||||||
|
text as *mut libc::c_void,
|
||||||
|
decoded
|
||||||
|
as *const libc::c_void,
|
||||||
|
decoded_len,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*text
|
||||||
|
.offset(decoded_len as isize) =
|
||||||
|
'\u{0}' as i32 as libc::c_char;
|
||||||
|
if 0 != opening_quote {
|
||||||
|
r = mailimf_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
'\"' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_ERROR_PARSE
|
||||||
|
as libc::c_int
|
||||||
|
{
|
||||||
|
missing_closing_quote = 1i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strcasecmp(
|
||||||
|
charset,
|
||||||
|
b"utf8\x00" as *const u8
|
||||||
|
as *const libc::c_char,
|
||||||
|
) == 0i32
|
||||||
|
{
|
||||||
|
free(
|
||||||
|
charset
|
||||||
|
as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
charset = strdup(
|
||||||
|
b"utf-8\x00" as *const u8
|
||||||
|
as *const libc::c_char,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ew = mailmime_encoded_word_new(
|
||||||
|
charset, text,
|
||||||
|
);
|
||||||
|
if ew.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY
|
||||||
|
as libc::c_int
|
||||||
|
} else {
|
||||||
|
*result = ew;
|
||||||
|
*indx = cur_token;
|
||||||
|
*p_has_fwd = has_fwd;
|
||||||
|
*p_missing_closing_quote =
|
||||||
|
missing_closing_quote;
|
||||||
|
mailmime_decoded_part_free(
|
||||||
|
decoded,
|
||||||
|
);
|
||||||
|
free(body as *mut libc::c_void);
|
||||||
|
return MAILIMF_NO_ERROR
|
||||||
|
as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mailmime_decoded_part_free(decoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(body as *mut libc::c_void);
|
||||||
|
mailmime_encoded_text_free(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mailmime_charset_free(charset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_encoding_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut libc::c_int,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut encoding: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
if cur_token >= length {
|
||||||
|
return MAILIMF_ERROR_PARSE as libc::c_int;
|
||||||
|
}
|
||||||
|
match toupper(*message.offset(cur_token as isize) as libc::c_uchar as libc::c_int)
|
||||||
|
as libc::c_char as libc::c_int
|
||||||
|
{
|
||||||
|
81 => encoding = MAILMIME_ENCODING_Q as libc::c_int,
|
||||||
|
66 => encoding = MAILMIME_ENCODING_B as libc::c_int,
|
||||||
|
_ => return MAILIMF_ERROR_INVAL as libc::c_int,
|
||||||
|
}
|
||||||
|
cur_token = cur_token.wrapping_add(1);
|
||||||
|
*result = encoding;
|
||||||
|
*indx = cur_token;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libEtPan! -- a mail stuff library
|
||||||
|
*
|
||||||
|
* Copyright (C) 2001, 2005 - DINH Viet Hoa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the libEtPan! project nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* $Id: mailmime_decode.c,v 1.37 2010/11/16 20:52:28 hoa Exp $
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
RFC 2047 : MIME (Multipurpose Internet Mail Extensions) Part Three:
|
||||||
|
Message Header Extensions for Non-ASCII Text
|
||||||
|
*/
|
||||||
|
unsafe fn mailmime_charset_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut charset: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_etoken_parse(message, length, indx, charset);
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_etoken_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailimf_custom_string_parse(message, length, indx, result, Some(is_etoken_char));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn is_etoken_char(mut ch: libc::c_char) -> libc::c_int {
|
||||||
|
let mut uch: libc::c_uchar = ch as libc::c_uchar;
|
||||||
|
if (uch as libc::c_int) < 31i32 {
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
match uch as libc::c_int {
|
||||||
|
32 | 40 | 41 | 60 | 62 | 64 | 44 | 59 | 58 | 34 | 47 | 91 | 93 | 63 | 61 => return 0i32,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return 1i32;
|
||||||
|
}
|
||||||
584
mmime/src/mailmime_disposition.rs
Normal file
584
mmime/src/mailmime_disposition.rs
Normal file
@@ -0,0 +1,584 @@
|
|||||||
|
use libc;
|
||||||
|
use libc::toupper;
|
||||||
|
|
||||||
|
use crate::clist::*;
|
||||||
|
use crate::mailimf::*;
|
||||||
|
use crate::mailmime::*;
|
||||||
|
use crate::mailmime_types::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
pub const MAILMIME_DISPOSITION_TYPE_EXTENSION: libc::c_uint = 3;
|
||||||
|
pub const MAILMIME_DISPOSITION_TYPE_ATTACHMENT: libc::c_uint = 2;
|
||||||
|
pub const MAILMIME_DISPOSITION_TYPE_INLINE: libc::c_uint = 1;
|
||||||
|
pub const MAILMIME_DISPOSITION_TYPE_ERROR: libc::c_uint = 0;
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut mailmime_disposition,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut current_block: u64;
|
||||||
|
let mut final_token: size_t = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut dsp_type: *mut mailmime_disposition_type = 0 as *mut mailmime_disposition_type;
|
||||||
|
let mut list: *mut clist = 0 as *mut clist;
|
||||||
|
let mut dsp: *mut mailmime_disposition = 0 as *mut mailmime_disposition;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailmime_disposition_type_parse(message, length, &mut cur_token, &mut dsp_type);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
list = clist_new();
|
||||||
|
if list.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int
|
||||||
|
} else {
|
||||||
|
loop {
|
||||||
|
let mut param: *mut mailmime_disposition_parm = 0 as *mut mailmime_disposition_parm;
|
||||||
|
final_token = cur_token;
|
||||||
|
r = mailimf_unstrict_char_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
';' as i32 as libc::c_char,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
param = 0 as *mut mailmime_disposition_parm;
|
||||||
|
r = mailmime_disposition_parm_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut param,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
r = clist_insert_after(list, (*list).last, param as *mut libc::c_void);
|
||||||
|
if !(r < 0i32) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
current_block = 18290070879695007868;
|
||||||
|
break;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
cur_token = final_token;
|
||||||
|
current_block = 652864300344834934;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
res = r;
|
||||||
|
current_block = 18290070879695007868;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 652864300344834934;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
res = r;
|
||||||
|
current_block = 18290070879695007868;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
652864300344834934 => {
|
||||||
|
dsp = mailmime_disposition_new(dsp_type, list);
|
||||||
|
if dsp.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int
|
||||||
|
} else {
|
||||||
|
*result = dsp;
|
||||||
|
*indx = cur_token;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
clist_foreach(
|
||||||
|
list,
|
||||||
|
::std::mem::transmute::<
|
||||||
|
Option<unsafe fn(_: *mut mailmime_disposition_parm) -> ()>,
|
||||||
|
clist_func,
|
||||||
|
>(Some(mailmime_disposition_parm_free)),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free(list);
|
||||||
|
}
|
||||||
|
mailmime_disposition_type_free(dsp_type);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* libEtPan! -- a mail stuff library
|
||||||
|
*
|
||||||
|
* Copyright (C) 2001, 2005 - DINH Viet Hoa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the libEtPan! project nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* $Id: mailmime_disposition.c,v 1.17 2011/05/03 16:30:22 hoa Exp $
|
||||||
|
*/
|
||||||
|
unsafe fn mailmime_disposition_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut mailmime_disposition_parm,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut current_block: u64;
|
||||||
|
let mut filename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut creation_date: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut modification_date: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut read_date: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut size: size_t = 0;
|
||||||
|
let mut parameter: *mut mailmime_parameter = 0 as *mut mailmime_parameter;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut dsp_parm: *mut mailmime_disposition_parm = 0 as *mut mailmime_disposition_parm;
|
||||||
|
let mut type_0: libc::c_int = 0;
|
||||||
|
let mut guessed_type: libc::c_int = 0;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
filename = 0 as *mut libc::c_char;
|
||||||
|
creation_date = 0 as *mut libc::c_char;
|
||||||
|
modification_date = 0 as *mut libc::c_char;
|
||||||
|
read_date = 0 as *mut libc::c_char;
|
||||||
|
size = 0i32 as size_t;
|
||||||
|
parameter = 0 as *mut mailmime_parameter;
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
guessed_type = mailmime_disposition_guess_type(message, length, cur_token);
|
||||||
|
type_0 = MAILMIME_DISPOSITION_PARM_PARAMETER as libc::c_int;
|
||||||
|
match guessed_type {
|
||||||
|
0 => {
|
||||||
|
r = mailmime_filename_parm_parse(message, length, &mut cur_token, &mut filename);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
r = mailmime_creation_date_parm_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut creation_date,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
r = mailmime_modification_date_parm_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
&mut modification_date,
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
r = mailmime_read_date_parm_parse(message, length, &mut cur_token, &mut read_date);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
r = mailmime_size_parm_parse(message, length, &mut cur_token, &mut size);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
} else {
|
||||||
|
/* do nothing */
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
current_block = 13826291924415791078;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
9120900589700563584 => {}
|
||||||
|
_ => {
|
||||||
|
if type_0 == MAILMIME_DISPOSITION_PARM_PARAMETER as libc::c_int {
|
||||||
|
r = mailmime_parameter_parse(message, length, &mut cur_token, &mut parameter);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = guessed_type;
|
||||||
|
res = r;
|
||||||
|
current_block = 9120900589700563584;
|
||||||
|
} else {
|
||||||
|
current_block = 6721012065216013753;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current_block = 6721012065216013753;
|
||||||
|
}
|
||||||
|
match current_block {
|
||||||
|
9120900589700563584 => {}
|
||||||
|
_ => {
|
||||||
|
dsp_parm = mailmime_disposition_parm_new(
|
||||||
|
type_0,
|
||||||
|
filename,
|
||||||
|
creation_date,
|
||||||
|
modification_date,
|
||||||
|
read_date,
|
||||||
|
size,
|
||||||
|
parameter,
|
||||||
|
);
|
||||||
|
if dsp_parm.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
if !filename.is_null() {
|
||||||
|
mailmime_filename_parm_free(filename);
|
||||||
|
}
|
||||||
|
if !creation_date.is_null() {
|
||||||
|
mailmime_creation_date_parm_free(creation_date);
|
||||||
|
}
|
||||||
|
if !modification_date.is_null() {
|
||||||
|
mailmime_modification_date_parm_free(modification_date);
|
||||||
|
}
|
||||||
|
if !read_date.is_null() {
|
||||||
|
mailmime_read_date_parm_free(read_date);
|
||||||
|
}
|
||||||
|
if !parameter.is_null() {
|
||||||
|
mailmime_parameter_free(parameter);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*result = dsp_parm;
|
||||||
|
*indx = cur_token;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_size_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut size_t,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut value: uint32_t = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"size\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"size\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_unstrict_char_parse(message, length, &mut cur_token, '=' as i32 as libc::c_char);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_number_parse(message, length, &mut cur_token, &mut value);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = value as size_t;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_read_date_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"read-date\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"read-date\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_unstrict_char_parse(message, length, &mut cur_token, '=' as i32 as libc::c_char);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailmime_quoted_date_time_parse(message, length, &mut cur_token, &mut value);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = value;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_quoted_date_time_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailimf_quoted_string_parse(message, length, indx, result);
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_modification_date_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"modification-date\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"modification-date\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_unstrict_char_parse(message, length, &mut cur_token, '=' as i32 as libc::c_char);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailmime_quoted_date_time_parse(message, length, &mut cur_token, &mut value);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = value;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_creation_date_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"creation-date\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"creation-date\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_unstrict_char_parse(message, length, &mut cur_token, '=' as i32 as libc::c_char);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailmime_quoted_date_time_parse(message, length, &mut cur_token, &mut value);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = value;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
unsafe fn mailmime_filename_parm_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut libc::c_char,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut value: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"filename\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"filename\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_unstrict_char_parse(message, length, &mut cur_token, '=' as i32 as libc::c_char);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = mailmime_value_parse(message, length, &mut cur_token, &mut value);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = value;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_guess_type(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: size_t,
|
||||||
|
) -> libc::c_int {
|
||||||
|
if indx >= length {
|
||||||
|
return MAILMIME_DISPOSITION_PARM_PARAMETER as libc::c_int;
|
||||||
|
}
|
||||||
|
match toupper(*message.offset(indx as isize) as libc::c_uchar as libc::c_int) as libc::c_char
|
||||||
|
as libc::c_int
|
||||||
|
{
|
||||||
|
70 => return MAILMIME_DISPOSITION_PARM_FILENAME as libc::c_int,
|
||||||
|
67 => return MAILMIME_DISPOSITION_PARM_CREATION_DATE as libc::c_int,
|
||||||
|
77 => return MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE as libc::c_int,
|
||||||
|
82 => return MAILMIME_DISPOSITION_PARM_READ_DATE as libc::c_int,
|
||||||
|
83 => return MAILMIME_DISPOSITION_PARM_SIZE as libc::c_int,
|
||||||
|
_ => return MAILMIME_DISPOSITION_PARM_PARAMETER as libc::c_int,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_type_parse(
|
||||||
|
mut message: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
mut indx: *mut size_t,
|
||||||
|
mut result: *mut *mut mailmime_disposition_type,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut cur_token: size_t = 0;
|
||||||
|
let mut type_0: libc::c_int = 0;
|
||||||
|
let mut extension: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
let mut dsp_type: *mut mailmime_disposition_type = 0 as *mut mailmime_disposition_type;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut res: libc::c_int = 0;
|
||||||
|
cur_token = *indx;
|
||||||
|
r = mailimf_cfws_parse(message, length, &mut cur_token);
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int && r != MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
type_0 = MAILMIME_DISPOSITION_TYPE_ERROR as libc::c_int;
|
||||||
|
extension = 0 as *mut libc::c_char;
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"inline\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"inline\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = MAILMIME_DISPOSITION_TYPE_INLINE as libc::c_int
|
||||||
|
}
|
||||||
|
if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
r = mailimf_token_case_insensitive_len_parse(
|
||||||
|
message,
|
||||||
|
length,
|
||||||
|
&mut cur_token,
|
||||||
|
b"attachment\x00" as *const u8 as *const libc::c_char as *mut libc::c_char,
|
||||||
|
strlen(b"attachment\x00" as *const u8 as *const libc::c_char),
|
||||||
|
);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = MAILMIME_DISPOSITION_TYPE_ATTACHMENT as libc::c_int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
|
r = mailmime_extension_token_parse(message, length, &mut cur_token, &mut extension);
|
||||||
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
type_0 = MAILMIME_DISPOSITION_TYPE_EXTENSION as libc::c_int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
|
res = r
|
||||||
|
} else {
|
||||||
|
dsp_type = mailmime_disposition_type_new(type_0, extension);
|
||||||
|
if dsp_type.is_null() {
|
||||||
|
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
||||||
|
if !extension.is_null() {
|
||||||
|
free(extension as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*result = dsp_type;
|
||||||
|
*indx = cur_token;
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
871
mmime/src/mailmime_types.rs
Normal file
871
mmime/src/mailmime_types.rs
Normal file
@@ -0,0 +1,871 @@
|
|||||||
|
use libc;
|
||||||
|
|
||||||
|
use crate::clist::*;
|
||||||
|
use crate::mailimf_types::*;
|
||||||
|
use crate::mmapstring::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
pub const MAILMIME_MECHANISM_TOKEN: libc::c_uint = 6;
|
||||||
|
pub const MAILMIME_MECHANISM_BASE64: libc::c_uint = 5;
|
||||||
|
pub const MAILMIME_MECHANISM_QUOTED_PRINTABLE: libc::c_uint = 4;
|
||||||
|
pub const MAILMIME_MECHANISM_BINARY: libc::c_uint = 3;
|
||||||
|
pub const MAILMIME_MECHANISM_8BIT: libc::c_uint = 2;
|
||||||
|
pub const MAILMIME_MECHANISM_7BIT: libc::c_uint = 1;
|
||||||
|
pub const MAILMIME_MECHANISM_ERROR: libc::c_uint = 0;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_composite_type {
|
||||||
|
pub ct_type: libc::c_int,
|
||||||
|
pub ct_token: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_content {
|
||||||
|
pub ct_type: *mut mailmime_type,
|
||||||
|
pub ct_subtype: *mut libc::c_char,
|
||||||
|
pub ct_parameters: *mut clist,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_type {
|
||||||
|
pub tp_type: libc::c_int,
|
||||||
|
pub tp_data: unnamed,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub union unnamed {
|
||||||
|
pub tp_discrete_type: *mut mailmime_discrete_type,
|
||||||
|
pub tp_composite_type: *mut mailmime_composite_type,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_discrete_type {
|
||||||
|
pub dt_type: libc::c_int,
|
||||||
|
pub dt_extension: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
pub type unnamed_0 = libc::c_uint;
|
||||||
|
pub const MAILMIME_FIELD_LOCATION: unnamed_0 = 8;
|
||||||
|
pub const MAILMIME_FIELD_LANGUAGE: unnamed_0 = 7;
|
||||||
|
pub const MAILMIME_FIELD_DISPOSITION: unnamed_0 = 6;
|
||||||
|
pub const MAILMIME_FIELD_VERSION: unnamed_0 = 5;
|
||||||
|
pub const MAILMIME_FIELD_DESCRIPTION: unnamed_0 = 4;
|
||||||
|
pub const MAILMIME_FIELD_ID: unnamed_0 = 3;
|
||||||
|
pub const MAILMIME_FIELD_TRANSFER_ENCODING: unnamed_0 = 2;
|
||||||
|
pub const MAILMIME_FIELD_TYPE: unnamed_0 = 1;
|
||||||
|
pub const MAILMIME_FIELD_NONE: unnamed_0 = 0;
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_field {
|
||||||
|
pub fld_type: libc::c_int,
|
||||||
|
pub fld_data: unnamed_1,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub union unnamed_1 {
|
||||||
|
pub fld_content: *mut mailmime_content,
|
||||||
|
pub fld_encoding: *mut mailmime_mechanism,
|
||||||
|
pub fld_id: *mut libc::c_char,
|
||||||
|
pub fld_description: *mut libc::c_char,
|
||||||
|
pub fld_version: uint32_t,
|
||||||
|
pub fld_disposition: *mut mailmime_disposition,
|
||||||
|
pub fld_language: *mut mailmime_language,
|
||||||
|
pub fld_location: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_language {
|
||||||
|
pub lg_list: *mut clist,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_disposition {
|
||||||
|
pub dsp_type: *mut mailmime_disposition_type,
|
||||||
|
pub dsp_parms: *mut clist,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_disposition_type {
|
||||||
|
pub dsp_type: libc::c_int,
|
||||||
|
pub dsp_extension: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_mechanism {
|
||||||
|
pub enc_type: libc::c_int,
|
||||||
|
pub enc_token: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_fields {
|
||||||
|
pub fld_list: *mut clist,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_parameter {
|
||||||
|
pub pa_name: *mut libc::c_char,
|
||||||
|
pub pa_value: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_disposition_parm {
|
||||||
|
pub pa_type: libc::c_int,
|
||||||
|
pub pa_data: unnamed_3,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub union unnamed_3 {
|
||||||
|
pub pa_filename: *mut libc::c_char,
|
||||||
|
pub pa_creation_date: *mut libc::c_char,
|
||||||
|
pub pa_modification_date: *mut libc::c_char,
|
||||||
|
pub pa_read_date: *mut libc::c_char,
|
||||||
|
pub pa_size: size_t,
|
||||||
|
pub pa_parameter: *mut mailmime_parameter,
|
||||||
|
}
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_PARAMETER: unnamed_11 = 5;
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_READ_DATE: unnamed_11 = 3;
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: unnamed_11 = 2;
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_CREATION_DATE: unnamed_11 = 1;
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_FILENAME: unnamed_11 = 0;
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_multipart_body {
|
||||||
|
pub bd_list: *mut clist,
|
||||||
|
}
|
||||||
|
pub type unnamed_4 = libc::c_uint;
|
||||||
|
pub const MAILMIME_DATA_FILE: unnamed_4 = 1;
|
||||||
|
pub const MAILMIME_DATA_TEXT: unnamed_4 = 0;
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_data {
|
||||||
|
pub dt_type: libc::c_int,
|
||||||
|
pub dt_encoding: libc::c_int,
|
||||||
|
pub dt_encoded: libc::c_int,
|
||||||
|
pub dt_data: unnamed_5,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub union unnamed_5 {
|
||||||
|
pub dt_text: unnamed_6,
|
||||||
|
pub dt_filename: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct unnamed_6 {
|
||||||
|
pub dt_data: *const libc::c_char,
|
||||||
|
pub dt_length: size_t,
|
||||||
|
}
|
||||||
|
pub type unnamed_7 = libc::c_uint;
|
||||||
|
pub const MAILMIME_MESSAGE: unnamed_7 = 3;
|
||||||
|
pub const MAILMIME_MULTIPLE: unnamed_7 = 2;
|
||||||
|
pub const MAILMIME_SINGLE: unnamed_7 = 1;
|
||||||
|
pub const MAILMIME_NONE: unnamed_7 = 0;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime {
|
||||||
|
pub mm_parent_type: libc::c_int,
|
||||||
|
pub mm_parent: *mut mailmime,
|
||||||
|
pub mm_multipart_pos: *mut clistiter,
|
||||||
|
pub mm_type: libc::c_int,
|
||||||
|
pub mm_mime_start: *const libc::c_char,
|
||||||
|
pub mm_length: size_t,
|
||||||
|
pub mm_mime_fields: *mut mailmime_fields,
|
||||||
|
pub mm_content_type: *mut mailmime_content,
|
||||||
|
pub mm_body: *mut mailmime_data,
|
||||||
|
pub mm_data: unnamed_8,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub union unnamed_8 {
|
||||||
|
pub mm_single: *mut mailmime_data,
|
||||||
|
pub mm_multipart: unnamed_10,
|
||||||
|
pub mm_message: unnamed_9,
|
||||||
|
}
|
||||||
|
/* message */
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct unnamed_9 {
|
||||||
|
pub mm_fields: *mut mailimf_fields,
|
||||||
|
pub mm_msg_mime: *mut mailmime,
|
||||||
|
}
|
||||||
|
/* multi-part */
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct unnamed_10 {
|
||||||
|
pub mm_preamble: *mut mailmime_data,
|
||||||
|
pub mm_epilogue: *mut mailmime_data,
|
||||||
|
pub mm_mp_list: *mut clist,
|
||||||
|
}
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_encoded_word {
|
||||||
|
pub wd_charset: *mut libc::c_char,
|
||||||
|
pub wd_text: *mut libc::c_char,
|
||||||
|
}
|
||||||
|
pub type unnamed_11 = libc::c_uint;
|
||||||
|
pub const MAILMIME_DISPOSITION_PARM_SIZE: unnamed_11 = 4;
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct mailmime_section {
|
||||||
|
pub sec_list: *mut clist,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_attribute_free(mut attribute: *mut libc::c_char) {
|
||||||
|
mailmime_token_free(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_token_free(mut token: *mut libc::c_char) {
|
||||||
|
free(token as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
pub unsafe fn mailmime_composite_type_new(
|
||||||
|
mut ct_type: libc::c_int,
|
||||||
|
mut ct_token: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_composite_type {
|
||||||
|
let mut ct: *mut mailmime_composite_type = 0 as *mut mailmime_composite_type;
|
||||||
|
ct = malloc(::std::mem::size_of::<mailmime_composite_type>() as libc::size_t)
|
||||||
|
as *mut mailmime_composite_type;
|
||||||
|
if ct.is_null() {
|
||||||
|
return 0 as *mut mailmime_composite_type;
|
||||||
|
}
|
||||||
|
(*ct).ct_type = ct_type;
|
||||||
|
(*ct).ct_token = ct_token;
|
||||||
|
return ct;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_composite_type_free(mut ct: *mut mailmime_composite_type) {
|
||||||
|
if !(*ct).ct_token.is_null() {
|
||||||
|
mailmime_extension_token_free((*ct).ct_token);
|
||||||
|
}
|
||||||
|
free(ct as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_extension_token_free(mut extension: *mut libc::c_char) {
|
||||||
|
mailmime_token_free(extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_content_new(
|
||||||
|
mut ct_type: *mut mailmime_type,
|
||||||
|
mut ct_subtype: *mut libc::c_char,
|
||||||
|
mut ct_parameters: *mut clist,
|
||||||
|
) -> *mut mailmime_content {
|
||||||
|
let mut content: *mut mailmime_content = 0 as *mut mailmime_content;
|
||||||
|
content =
|
||||||
|
malloc(::std::mem::size_of::<mailmime_content>() as libc::size_t) as *mut mailmime_content;
|
||||||
|
if content.is_null() {
|
||||||
|
return 0 as *mut mailmime_content;
|
||||||
|
}
|
||||||
|
(*content).ct_type = ct_type;
|
||||||
|
(*content).ct_subtype = ct_subtype;
|
||||||
|
(*content).ct_parameters = ct_parameters;
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_content_free(mut content: *mut mailmime_content) {
|
||||||
|
mailmime_type_free((*content).ct_type);
|
||||||
|
mailmime_subtype_free((*content).ct_subtype);
|
||||||
|
if !(*content).ct_parameters.is_null() {
|
||||||
|
clist_foreach(
|
||||||
|
(*content).ct_parameters,
|
||||||
|
::std::mem::transmute::<Option<unsafe fn(_: *mut mailmime_parameter) -> ()>, clist_func>(
|
||||||
|
Some(mailmime_parameter_free),
|
||||||
|
),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*content).ct_parameters);
|
||||||
|
}
|
||||||
|
free(content as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_parameter_free(mut parameter: *mut mailmime_parameter) {
|
||||||
|
mailmime_attribute_free((*parameter).pa_name);
|
||||||
|
mailmime_value_free((*parameter).pa_value);
|
||||||
|
free(parameter as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_value_free(mut value: *mut libc::c_char) {
|
||||||
|
free(value as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_subtype_free(mut subtype: *mut libc::c_char) {
|
||||||
|
mailmime_extension_token_free(subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_type_free(mut type_0: *mut mailmime_type) {
|
||||||
|
match (*type_0).tp_type {
|
||||||
|
1 => {
|
||||||
|
mailmime_discrete_type_free((*type_0).tp_data.tp_discrete_type);
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
mailmime_composite_type_free((*type_0).tp_data.tp_composite_type);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(type_0 as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_discrete_type_free(mut discrete_type: *mut mailmime_discrete_type) {
|
||||||
|
if !(*discrete_type).dt_extension.is_null() {
|
||||||
|
mailmime_extension_token_free((*discrete_type).dt_extension);
|
||||||
|
}
|
||||||
|
free(discrete_type as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_description_free(mut description: *mut libc::c_char) {
|
||||||
|
free(description as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_location_free(mut location: *mut libc::c_char) {
|
||||||
|
free(location as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_discrete_type_new(
|
||||||
|
mut dt_type: libc::c_int,
|
||||||
|
mut dt_extension: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_discrete_type {
|
||||||
|
let mut discrete_type: *mut mailmime_discrete_type = 0 as *mut mailmime_discrete_type;
|
||||||
|
discrete_type = malloc(::std::mem::size_of::<mailmime_discrete_type>() as libc::size_t)
|
||||||
|
as *mut mailmime_discrete_type;
|
||||||
|
if discrete_type.is_null() {
|
||||||
|
return 0 as *mut mailmime_discrete_type;
|
||||||
|
}
|
||||||
|
(*discrete_type).dt_type = dt_type;
|
||||||
|
(*discrete_type).dt_extension = dt_extension;
|
||||||
|
return discrete_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoding_free(mut encoding: *mut mailmime_mechanism) {
|
||||||
|
mailmime_mechanism_free(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_mechanism_free(mut mechanism: *mut mailmime_mechanism) {
|
||||||
|
if !(*mechanism).enc_token.is_null() {
|
||||||
|
mailmime_token_free((*mechanism).enc_token);
|
||||||
|
}
|
||||||
|
free(mechanism as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_id_free(mut id: *mut libc::c_char) {
|
||||||
|
mailimf_msg_id_free(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_mechanism_new(
|
||||||
|
mut enc_type: libc::c_int,
|
||||||
|
mut enc_token: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_mechanism {
|
||||||
|
let mut mechanism: *mut mailmime_mechanism = 0 as *mut mailmime_mechanism;
|
||||||
|
mechanism = malloc(::std::mem::size_of::<mailmime_mechanism>() as libc::size_t)
|
||||||
|
as *mut mailmime_mechanism;
|
||||||
|
if mechanism.is_null() {
|
||||||
|
return 0 as *mut mailmime_mechanism;
|
||||||
|
}
|
||||||
|
(*mechanism).enc_type = enc_type;
|
||||||
|
(*mechanism).enc_token = enc_token;
|
||||||
|
return mechanism;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_parameter_new(
|
||||||
|
mut pa_name: *mut libc::c_char,
|
||||||
|
mut pa_value: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_parameter {
|
||||||
|
let mut parameter: *mut mailmime_parameter = 0 as *mut mailmime_parameter;
|
||||||
|
parameter = malloc(::std::mem::size_of::<mailmime_parameter>() as libc::size_t)
|
||||||
|
as *mut mailmime_parameter;
|
||||||
|
if parameter.is_null() {
|
||||||
|
return 0 as *mut mailmime_parameter;
|
||||||
|
}
|
||||||
|
(*parameter).pa_name = pa_name;
|
||||||
|
(*parameter).pa_value = pa_value;
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_type_new(
|
||||||
|
mut tp_type: libc::c_int,
|
||||||
|
mut tp_discrete_type: *mut mailmime_discrete_type,
|
||||||
|
mut tp_composite_type: *mut mailmime_composite_type,
|
||||||
|
) -> *mut mailmime_type {
|
||||||
|
let mut mime_type: *mut mailmime_type = 0 as *mut mailmime_type;
|
||||||
|
mime_type =
|
||||||
|
malloc(::std::mem::size_of::<mailmime_type>() as libc::size_t) as *mut mailmime_type;
|
||||||
|
if mime_type.is_null() {
|
||||||
|
return 0 as *mut mailmime_type;
|
||||||
|
}
|
||||||
|
(*mime_type).tp_type = tp_type;
|
||||||
|
match tp_type {
|
||||||
|
1 => (*mime_type).tp_data.tp_discrete_type = tp_discrete_type,
|
||||||
|
2 => (*mime_type).tp_data.tp_composite_type = tp_composite_type,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return mime_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_language_new(mut lg_list: *mut clist) -> *mut mailmime_language {
|
||||||
|
let mut lang: *mut mailmime_language = 0 as *mut mailmime_language;
|
||||||
|
lang = malloc(::std::mem::size_of::<mailmime_language>() as libc::size_t)
|
||||||
|
as *mut mailmime_language;
|
||||||
|
if lang.is_null() {
|
||||||
|
return 0 as *mut mailmime_language;
|
||||||
|
}
|
||||||
|
(*lang).lg_list = lg_list;
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_language_free(mut lang: *mut mailmime_language) {
|
||||||
|
clist_foreach(
|
||||||
|
(*lang).lg_list,
|
||||||
|
::std::mem::transmute::<Option<unsafe fn(_: *mut libc::c_char) -> ()>, clist_func>(Some(
|
||||||
|
mailimf_atom_free,
|
||||||
|
)),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*lang).lg_list);
|
||||||
|
free(lang as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
void mailmime_x_token_free(gchar * x_token);
|
||||||
|
*/
|
||||||
|
pub unsafe fn mailmime_field_new(
|
||||||
|
mut fld_type: libc::c_int,
|
||||||
|
mut fld_content: *mut mailmime_content,
|
||||||
|
mut fld_encoding: *mut mailmime_mechanism,
|
||||||
|
mut fld_id: *mut libc::c_char,
|
||||||
|
mut fld_description: *mut libc::c_char,
|
||||||
|
mut fld_version: uint32_t,
|
||||||
|
mut fld_disposition: *mut mailmime_disposition,
|
||||||
|
mut fld_language: *mut mailmime_language,
|
||||||
|
mut fld_location: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_field {
|
||||||
|
let mut field: *mut mailmime_field = 0 as *mut mailmime_field;
|
||||||
|
field = malloc(::std::mem::size_of::<mailmime_field>() as libc::size_t) as *mut mailmime_field;
|
||||||
|
if field.is_null() {
|
||||||
|
return 0 as *mut mailmime_field;
|
||||||
|
}
|
||||||
|
(*field).fld_type = fld_type;
|
||||||
|
match fld_type {
|
||||||
|
1 => (*field).fld_data.fld_content = fld_content,
|
||||||
|
2 => (*field).fld_data.fld_encoding = fld_encoding,
|
||||||
|
3 => (*field).fld_data.fld_id = fld_id,
|
||||||
|
4 => (*field).fld_data.fld_description = fld_description,
|
||||||
|
5 => (*field).fld_data.fld_version = fld_version,
|
||||||
|
6 => (*field).fld_data.fld_disposition = fld_disposition,
|
||||||
|
7 => (*field).fld_data.fld_language = fld_language,
|
||||||
|
8 => (*field).fld_data.fld_location = fld_location,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_field_free(mut field: *mut mailmime_field) {
|
||||||
|
match (*field).fld_type {
|
||||||
|
1 => {
|
||||||
|
if !(*field).fld_data.fld_content.is_null() {
|
||||||
|
mailmime_content_free((*field).fld_data.fld_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
if !(*field).fld_data.fld_encoding.is_null() {
|
||||||
|
mailmime_encoding_free((*field).fld_data.fld_encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
if !(*field).fld_data.fld_id.is_null() {
|
||||||
|
mailmime_id_free((*field).fld_data.fld_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
if !(*field).fld_data.fld_description.is_null() {
|
||||||
|
mailmime_description_free((*field).fld_data.fld_description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
if !(*field).fld_data.fld_disposition.is_null() {
|
||||||
|
mailmime_disposition_free((*field).fld_data.fld_disposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
7 => {
|
||||||
|
if !(*field).fld_data.fld_language.is_null() {
|
||||||
|
mailmime_language_free((*field).fld_data.fld_language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
8 => {
|
||||||
|
if !(*field).fld_data.fld_location.is_null() {
|
||||||
|
mailmime_location_free((*field).fld_data.fld_location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(field as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_free(mut dsp: *mut mailmime_disposition) {
|
||||||
|
mailmime_disposition_type_free((*dsp).dsp_type);
|
||||||
|
clist_foreach(
|
||||||
|
(*dsp).dsp_parms,
|
||||||
|
::std::mem::transmute::<
|
||||||
|
Option<unsafe fn(_: *mut mailmime_disposition_parm) -> ()>,
|
||||||
|
clist_func,
|
||||||
|
>(Some(mailmime_disposition_parm_free)),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*dsp).dsp_parms);
|
||||||
|
free(dsp as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_parm_free(mut dsp_parm: *mut mailmime_disposition_parm) {
|
||||||
|
match (*dsp_parm).pa_type {
|
||||||
|
0 => {
|
||||||
|
mailmime_filename_parm_free((*dsp_parm).pa_data.pa_filename);
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
mailmime_creation_date_parm_free((*dsp_parm).pa_data.pa_creation_date);
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
mailmime_modification_date_parm_free((*dsp_parm).pa_data.pa_modification_date);
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
mailmime_read_date_parm_free((*dsp_parm).pa_data.pa_read_date);
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
|
mailmime_parameter_free((*dsp_parm).pa_data.pa_parameter);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(dsp_parm as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_read_date_parm_free(mut date: *mut libc::c_char) {
|
||||||
|
mailmime_quoted_date_time_free(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_quoted_date_time_free(mut date: *mut libc::c_char) {
|
||||||
|
mailimf_quoted_string_free(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_modification_date_parm_free(mut date: *mut libc::c_char) {
|
||||||
|
mailmime_quoted_date_time_free(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_creation_date_parm_free(mut date: *mut libc::c_char) {
|
||||||
|
mailmime_quoted_date_time_free(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_filename_parm_free(mut filename: *mut libc::c_char) {
|
||||||
|
mailmime_value_free(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_type_free(mut dsp_type: *mut mailmime_disposition_type) {
|
||||||
|
if !(*dsp_type).dsp_extension.is_null() {
|
||||||
|
free((*dsp_type).dsp_extension as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
free(dsp_type as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_fields_new(mut fld_list: *mut clist) -> *mut mailmime_fields {
|
||||||
|
let mut fields: *mut mailmime_fields = 0 as *mut mailmime_fields;
|
||||||
|
fields =
|
||||||
|
malloc(::std::mem::size_of::<mailmime_fields>() as libc::size_t) as *mut mailmime_fields;
|
||||||
|
if fields.is_null() {
|
||||||
|
return 0 as *mut mailmime_fields;
|
||||||
|
}
|
||||||
|
(*fields).fld_list = fld_list;
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_fields_free(mut fields: *mut mailmime_fields) {
|
||||||
|
clist_foreach(
|
||||||
|
(*fields).fld_list,
|
||||||
|
::std::mem::transmute::<Option<unsafe fn(_: *mut mailmime_field) -> ()>, clist_func>(Some(
|
||||||
|
mailmime_field_free,
|
||||||
|
)),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*fields).fld_list);
|
||||||
|
free(fields as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_multipart_body_new(mut bd_list: *mut clist) -> *mut mailmime_multipart_body {
|
||||||
|
let mut mp_body: *mut mailmime_multipart_body = 0 as *mut mailmime_multipart_body;
|
||||||
|
mp_body = malloc(::std::mem::size_of::<mailmime_multipart_body>() as libc::size_t)
|
||||||
|
as *mut mailmime_multipart_body;
|
||||||
|
if mp_body.is_null() {
|
||||||
|
return 0 as *mut mailmime_multipart_body;
|
||||||
|
}
|
||||||
|
(*mp_body).bd_list = bd_list;
|
||||||
|
return mp_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_multipart_body_free(mut mp_body: *mut mailmime_multipart_body) {
|
||||||
|
clist_foreach(
|
||||||
|
(*mp_body).bd_list,
|
||||||
|
::std::mem::transmute::<Option<unsafe fn(_: *mut mailimf_body) -> ()>, clist_func>(Some(
|
||||||
|
mailimf_body_free,
|
||||||
|
)),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*mp_body).bd_list);
|
||||||
|
free(mp_body as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_data_new(
|
||||||
|
mut dt_type: libc::c_int,
|
||||||
|
mut dt_encoding: libc::c_int,
|
||||||
|
mut dt_encoded: libc::c_int,
|
||||||
|
mut dt_data: *const libc::c_char,
|
||||||
|
mut dt_length: size_t,
|
||||||
|
mut dt_filename: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_data {
|
||||||
|
let mut mime_data: *mut mailmime_data = 0 as *mut mailmime_data;
|
||||||
|
mime_data =
|
||||||
|
malloc(::std::mem::size_of::<mailmime_data>() as libc::size_t) as *mut mailmime_data;
|
||||||
|
if mime_data.is_null() {
|
||||||
|
return 0 as *mut mailmime_data;
|
||||||
|
}
|
||||||
|
(*mime_data).dt_type = dt_type;
|
||||||
|
(*mime_data).dt_encoding = dt_encoding;
|
||||||
|
(*mime_data).dt_encoded = dt_encoded;
|
||||||
|
match dt_type {
|
||||||
|
0 => {
|
||||||
|
(*mime_data).dt_data.dt_text.dt_data = dt_data;
|
||||||
|
(*mime_data).dt_data.dt_text.dt_length = dt_length
|
||||||
|
}
|
||||||
|
1 => (*mime_data).dt_data.dt_filename = dt_filename,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return mime_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_data_free(mut mime_data: *mut mailmime_data) {
|
||||||
|
match (*mime_data).dt_type {
|
||||||
|
1 => {
|
||||||
|
free((*mime_data).dt_data.dt_filename as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
free(mime_data as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_new(
|
||||||
|
mut mm_type: libc::c_int,
|
||||||
|
mut mm_mime_start: *const libc::c_char,
|
||||||
|
mut mm_length: size_t,
|
||||||
|
mut mm_mime_fields: *mut mailmime_fields,
|
||||||
|
mut mm_content_type: *mut mailmime_content,
|
||||||
|
mut mm_body: *mut mailmime_data,
|
||||||
|
mut mm_preamble: *mut mailmime_data,
|
||||||
|
mut mm_epilogue: *mut mailmime_data,
|
||||||
|
mut mm_mp_list: *mut clist,
|
||||||
|
mut mm_fields: *mut mailimf_fields,
|
||||||
|
mut mm_msg_mime: *mut mailmime,
|
||||||
|
) -> *mut mailmime {
|
||||||
|
let mut mime: *mut mailmime = 0 as *mut mailmime;
|
||||||
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
|
mime = malloc(::std::mem::size_of::<mailmime>() as libc::size_t) as *mut mailmime;
|
||||||
|
if mime.is_null() {
|
||||||
|
return 0 as *mut mailmime;
|
||||||
|
}
|
||||||
|
(*mime).mm_parent = 0 as *mut mailmime;
|
||||||
|
(*mime).mm_parent_type = MAILMIME_NONE as libc::c_int;
|
||||||
|
(*mime).mm_multipart_pos = 0 as *mut clistiter;
|
||||||
|
(*mime).mm_type = mm_type;
|
||||||
|
(*mime).mm_mime_start = mm_mime_start;
|
||||||
|
(*mime).mm_length = mm_length;
|
||||||
|
(*mime).mm_mime_fields = mm_mime_fields;
|
||||||
|
(*mime).mm_content_type = mm_content_type;
|
||||||
|
(*mime).mm_body = mm_body;
|
||||||
|
match mm_type {
|
||||||
|
1 => (*mime).mm_data.mm_single = mm_body,
|
||||||
|
2 => {
|
||||||
|
(*mime).mm_data.mm_multipart.mm_preamble = mm_preamble;
|
||||||
|
(*mime).mm_data.mm_multipart.mm_epilogue = mm_epilogue;
|
||||||
|
(*mime).mm_data.mm_multipart.mm_mp_list = mm_mp_list;
|
||||||
|
cur = (*mm_mp_list).first;
|
||||||
|
while !cur.is_null() {
|
||||||
|
let mut submime: *mut mailmime = 0 as *mut mailmime;
|
||||||
|
submime = (if !cur.is_null() {
|
||||||
|
(*cur).data
|
||||||
|
} else {
|
||||||
|
0 as *mut libc::c_void
|
||||||
|
}) as *mut mailmime;
|
||||||
|
(*submime).mm_parent = mime;
|
||||||
|
(*submime).mm_parent_type = MAILMIME_MULTIPLE as libc::c_int;
|
||||||
|
(*submime).mm_multipart_pos = cur;
|
||||||
|
cur = if !cur.is_null() {
|
||||||
|
(*cur).next
|
||||||
|
} else {
|
||||||
|
0 as *mut clistcell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
(*mime).mm_data.mm_message.mm_fields = mm_fields;
|
||||||
|
(*mime).mm_data.mm_message.mm_msg_mime = mm_msg_mime;
|
||||||
|
if !mm_msg_mime.is_null() {
|
||||||
|
(*mm_msg_mime).mm_parent = mime;
|
||||||
|
(*mm_msg_mime).mm_parent_type = MAILMIME_MESSAGE as libc::c_int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_free(mut mime: *mut mailmime) {
|
||||||
|
match (*mime).mm_type {
|
||||||
|
1 => {
|
||||||
|
if (*mime).mm_body.is_null() && !(*mime).mm_data.mm_single.is_null() {
|
||||||
|
mailmime_data_free((*mime).mm_data.mm_single);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
/* do nothing */
|
||||||
|
if !(*mime).mm_data.mm_multipart.mm_preamble.is_null() {
|
||||||
|
mailmime_data_free((*mime).mm_data.mm_multipart.mm_preamble);
|
||||||
|
}
|
||||||
|
if !(*mime).mm_data.mm_multipart.mm_epilogue.is_null() {
|
||||||
|
mailmime_data_free((*mime).mm_data.mm_multipart.mm_epilogue);
|
||||||
|
}
|
||||||
|
clist_foreach(
|
||||||
|
(*mime).mm_data.mm_multipart.mm_mp_list,
|
||||||
|
::std::mem::transmute::<Option<unsafe fn(_: *mut mailmime) -> ()>, clist_func>(
|
||||||
|
Some(mailmime_free),
|
||||||
|
),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*mime).mm_data.mm_multipart.mm_mp_list);
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
if !(*mime).mm_data.mm_message.mm_fields.is_null() {
|
||||||
|
mailimf_fields_free((*mime).mm_data.mm_message.mm_fields);
|
||||||
|
}
|
||||||
|
if !(*mime).mm_data.mm_message.mm_msg_mime.is_null() {
|
||||||
|
mailmime_free((*mime).mm_data.mm_message.mm_msg_mime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if !(*mime).mm_body.is_null() {
|
||||||
|
mailmime_data_free((*mime).mm_body);
|
||||||
|
}
|
||||||
|
if !(*mime).mm_mime_fields.is_null() {
|
||||||
|
mailmime_fields_free((*mime).mm_mime_fields);
|
||||||
|
}
|
||||||
|
if !(*mime).mm_content_type.is_null() {
|
||||||
|
mailmime_content_free((*mime).mm_content_type);
|
||||||
|
}
|
||||||
|
free(mime as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoded_word_new(
|
||||||
|
mut wd_charset: *mut libc::c_char,
|
||||||
|
mut wd_text: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_encoded_word {
|
||||||
|
let mut ew: *mut mailmime_encoded_word = 0 as *mut mailmime_encoded_word;
|
||||||
|
ew = malloc(::std::mem::size_of::<mailmime_encoded_word>() as libc::size_t)
|
||||||
|
as *mut mailmime_encoded_word;
|
||||||
|
if ew.is_null() {
|
||||||
|
return 0 as *mut mailmime_encoded_word;
|
||||||
|
}
|
||||||
|
(*ew).wd_charset = wd_charset;
|
||||||
|
(*ew).wd_text = wd_text;
|
||||||
|
return ew;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoded_word_free(mut ew: *mut mailmime_encoded_word) {
|
||||||
|
mailmime_charset_free((*ew).wd_charset);
|
||||||
|
mailmime_encoded_text_free((*ew).wd_text);
|
||||||
|
free(ew as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_encoded_text_free(mut text: *mut libc::c_char) {
|
||||||
|
free(text as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_charset_free(mut charset: *mut libc::c_char) {
|
||||||
|
free(charset as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_new(
|
||||||
|
mut dsp_type: *mut mailmime_disposition_type,
|
||||||
|
mut dsp_parms: *mut clist,
|
||||||
|
) -> *mut mailmime_disposition {
|
||||||
|
let mut dsp: *mut mailmime_disposition = 0 as *mut mailmime_disposition;
|
||||||
|
dsp = malloc(::std::mem::size_of::<mailmime_disposition>() as libc::size_t)
|
||||||
|
as *mut mailmime_disposition;
|
||||||
|
if dsp.is_null() {
|
||||||
|
return 0 as *mut mailmime_disposition;
|
||||||
|
}
|
||||||
|
(*dsp).dsp_type = dsp_type;
|
||||||
|
(*dsp).dsp_parms = dsp_parms;
|
||||||
|
return dsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_type_new(
|
||||||
|
mut dsp_type: libc::c_int,
|
||||||
|
mut dsp_extension: *mut libc::c_char,
|
||||||
|
) -> *mut mailmime_disposition_type {
|
||||||
|
let mut m_dsp_type: *mut mailmime_disposition_type = 0 as *mut mailmime_disposition_type;
|
||||||
|
m_dsp_type = malloc(::std::mem::size_of::<mailmime_disposition_type>() as libc::size_t)
|
||||||
|
as *mut mailmime_disposition_type;
|
||||||
|
if m_dsp_type.is_null() {
|
||||||
|
return 0 as *mut mailmime_disposition_type;
|
||||||
|
}
|
||||||
|
(*m_dsp_type).dsp_type = dsp_type;
|
||||||
|
(*m_dsp_type).dsp_extension = dsp_extension;
|
||||||
|
return m_dsp_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_disposition_parm_new(
|
||||||
|
mut pa_type: libc::c_int,
|
||||||
|
mut pa_filename: *mut libc::c_char,
|
||||||
|
mut pa_creation_date: *mut libc::c_char,
|
||||||
|
mut pa_modification_date: *mut libc::c_char,
|
||||||
|
mut pa_read_date: *mut libc::c_char,
|
||||||
|
mut pa_size: size_t,
|
||||||
|
mut pa_parameter: *mut mailmime_parameter,
|
||||||
|
) -> *mut mailmime_disposition_parm {
|
||||||
|
let mut dsp_parm: *mut mailmime_disposition_parm = 0 as *mut mailmime_disposition_parm;
|
||||||
|
dsp_parm = malloc(::std::mem::size_of::<mailmime_disposition_parm>() as libc::size_t)
|
||||||
|
as *mut mailmime_disposition_parm;
|
||||||
|
if dsp_parm.is_null() {
|
||||||
|
return 0 as *mut mailmime_disposition_parm;
|
||||||
|
}
|
||||||
|
(*dsp_parm).pa_type = pa_type;
|
||||||
|
match pa_type {
|
||||||
|
0 => (*dsp_parm).pa_data.pa_filename = pa_filename,
|
||||||
|
1 => (*dsp_parm).pa_data.pa_creation_date = pa_creation_date,
|
||||||
|
2 => (*dsp_parm).pa_data.pa_modification_date = pa_modification_date,
|
||||||
|
3 => (*dsp_parm).pa_data.pa_read_date = pa_read_date,
|
||||||
|
4 => (*dsp_parm).pa_data.pa_size = pa_size,
|
||||||
|
5 => (*dsp_parm).pa_data.pa_parameter = pa_parameter,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return dsp_parm;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_section_new(mut sec_list: *mut clist) -> *mut mailmime_section {
|
||||||
|
let mut section: *mut mailmime_section = 0 as *mut mailmime_section;
|
||||||
|
section =
|
||||||
|
malloc(::std::mem::size_of::<mailmime_section>() as libc::size_t) as *mut mailmime_section;
|
||||||
|
if section.is_null() {
|
||||||
|
return 0 as *mut mailmime_section;
|
||||||
|
}
|
||||||
|
(*section).sec_list = sec_list;
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_section_free(mut section: *mut mailmime_section) {
|
||||||
|
clist_foreach(
|
||||||
|
(*section).sec_list,
|
||||||
|
::std::mem::transmute::<Option<unsafe extern "C" fn(_: *mut libc::c_void) -> ()>, clist_func>(
|
||||||
|
Some(free),
|
||||||
|
),
|
||||||
|
0 as *mut libc::c_void,
|
||||||
|
);
|
||||||
|
clist_free((*section).sec_list);
|
||||||
|
free(section as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_decoded_part_free(mut part: *mut libc::c_char) {
|
||||||
|
mmap_string_unref(part);
|
||||||
|
}
|
||||||
1446
mmime/src/mailmime_types_helper.rs
Normal file
1446
mmime/src/mailmime_types_helper.rs
Normal file
File diff suppressed because it is too large
Load Diff
1979
mmime/src/mailmime_write_generic.rs
Normal file
1979
mmime/src/mailmime_write_generic.rs
Normal file
File diff suppressed because it is too large
Load Diff
82
mmime/src/mailmime_write_mem.rs
Normal file
82
mmime/src/mailmime_write_mem.rs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
use crate::mailmime_types::*;
|
||||||
|
use crate::mailmime_write_generic::*;
|
||||||
|
use crate::mmapstring::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
unsafe fn do_write(
|
||||||
|
mut data: *mut libc::c_void,
|
||||||
|
mut str: *const libc::c_char,
|
||||||
|
mut length: size_t,
|
||||||
|
) -> libc::c_int {
|
||||||
|
let mut f: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
f = data as *mut MMAPString;
|
||||||
|
if mmap_string_append_len(f, str, length).is_null() {
|
||||||
|
return 0i32;
|
||||||
|
} else {
|
||||||
|
return length as libc::c_int;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_content_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut content: *mut mailmime_content,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_content_write_driver(Some(do_write), f as *mut libc::c_void, col, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_content_type_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut content: *mut mailmime_content,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_content_type_write_driver(
|
||||||
|
Some(do_write),
|
||||||
|
f as *mut libc::c_void,
|
||||||
|
col,
|
||||||
|
content,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut build_info: *mut mailmime,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_write_driver(Some(do_write), f as *mut libc::c_void, col, build_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_quoted_printable_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut istext: libc::c_int,
|
||||||
|
mut text: *const libc::c_char,
|
||||||
|
mut size: size_t,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_quoted_printable_write_driver(
|
||||||
|
Some(do_write),
|
||||||
|
f as *mut libc::c_void,
|
||||||
|
col,
|
||||||
|
istext,
|
||||||
|
text,
|
||||||
|
size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_base64_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut text: *const libc::c_char,
|
||||||
|
mut size: size_t,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_base64_write_driver(Some(do_write), f as *mut libc::c_void, col, text, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailmime_data_write_mem(
|
||||||
|
mut f: *mut MMAPString,
|
||||||
|
mut col: *mut libc::c_int,
|
||||||
|
mut data: *mut mailmime_data,
|
||||||
|
mut istext: libc::c_int,
|
||||||
|
) -> libc::c_int {
|
||||||
|
return mailmime_data_write_driver(Some(do_write), f as *mut libc::c_void, col, data, istext);
|
||||||
|
}
|
||||||
397
mmime/src/mmapstring.rs
Normal file
397
mmime/src/mmapstring.rs
Normal file
@@ -0,0 +1,397 @@
|
|||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use libc;
|
||||||
|
|
||||||
|
use crate::chash::*;
|
||||||
|
use crate::other::*;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref mmapstring_lock: Mutex<()> = Mutex::new(());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct MMAPString {
|
||||||
|
pub str_0: *mut libc::c_char,
|
||||||
|
pub len: size_t,
|
||||||
|
pub allocated_len: size_t,
|
||||||
|
pub fd: libc::c_int,
|
||||||
|
pub mmapped_size: size_t,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const TMPDIR: &'static str = "/tmp";
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_new(mut init: *const libc::c_char) -> *mut MMAPString {
|
||||||
|
let mut string: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
string = mmap_string_sized_new(if !init.is_null() {
|
||||||
|
strlen(init).wrapping_add(2i32 as libc::size_t)
|
||||||
|
} else {
|
||||||
|
2i32 as libc::size_t
|
||||||
|
});
|
||||||
|
if string.is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
if !init.is_null() {
|
||||||
|
mmap_string_append(string, init);
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_append(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_len(string, (*string).len, val, strlen(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_insert_len(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut pos: size_t,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
if mmap_string_maybe_expand(string, len).is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
if pos < (*string).len {
|
||||||
|
memmove(
|
||||||
|
(*string).str_0.offset(pos as isize).offset(len as isize) as *mut libc::c_void,
|
||||||
|
(*string).str_0.offset(pos as isize) as *const libc::c_void,
|
||||||
|
(*string).len.wrapping_sub(pos),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
memmove(
|
||||||
|
(*string).str_0.offset(pos as isize) as *mut libc::c_void,
|
||||||
|
val as *const libc::c_void,
|
||||||
|
len,
|
||||||
|
);
|
||||||
|
(*string).len = ((*string).len as libc::size_t).wrapping_add(len) as size_t as size_t;
|
||||||
|
*(*string).str_0.offset((*string).len as isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
unsafe fn mmap_string_maybe_expand(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
if (*string).len.wrapping_add(len) >= (*string).allocated_len {
|
||||||
|
let mut old_size: size_t = 0;
|
||||||
|
let mut newstring: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
old_size = (*string).allocated_len;
|
||||||
|
(*string).allocated_len = nearest_power(
|
||||||
|
1i32 as size_t,
|
||||||
|
(*string)
|
||||||
|
.len
|
||||||
|
.wrapping_add(len)
|
||||||
|
.wrapping_add(1i32 as libc::size_t),
|
||||||
|
);
|
||||||
|
newstring = mmap_string_realloc_memory(string);
|
||||||
|
if newstring.is_null() {
|
||||||
|
(*string).allocated_len = old_size
|
||||||
|
}
|
||||||
|
return newstring;
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
/* Strings.
|
||||||
|
*/
|
||||||
|
/* SEB */
|
||||||
|
unsafe fn mmap_string_realloc_memory(mut string: *mut MMAPString) -> *mut MMAPString {
|
||||||
|
let mut tmp: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
|
tmp = realloc(
|
||||||
|
(*string).str_0 as *mut libc::c_void,
|
||||||
|
(*string).allocated_len,
|
||||||
|
) as *mut libc::c_char;
|
||||||
|
if tmp.is_null() {
|
||||||
|
string = 0 as *mut MMAPString
|
||||||
|
} else {
|
||||||
|
(*string).str_0 = tmp
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
/* MMAPString */
|
||||||
|
#[inline]
|
||||||
|
unsafe fn nearest_power(mut base: size_t, mut num: size_t) -> size_t {
|
||||||
|
if num > (-1i32 as size_t).wrapping_div(2i32 as libc::size_t) {
|
||||||
|
return -1i32 as size_t;
|
||||||
|
} else {
|
||||||
|
let mut n: size_t = base;
|
||||||
|
while n < num {
|
||||||
|
n <<= 1i32
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_sized_new(mut dfl_size: size_t) -> *mut MMAPString {
|
||||||
|
let mut string: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
string = malloc(::std::mem::size_of::<MMAPString>() as libc::size_t) as *mut MMAPString;
|
||||||
|
if string.is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
(*string).allocated_len = 0i32 as size_t;
|
||||||
|
(*string).len = 0i32 as size_t;
|
||||||
|
(*string).str_0 = 0 as *mut libc::c_char;
|
||||||
|
(*string).fd = -1i32;
|
||||||
|
(*string).mmapped_size = 0i32 as size_t;
|
||||||
|
if mmap_string_maybe_expand(
|
||||||
|
string,
|
||||||
|
if dfl_size > 2i32 as libc::size_t {
|
||||||
|
dfl_size
|
||||||
|
} else {
|
||||||
|
2i32 as libc::size_t
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.is_null()
|
||||||
|
{
|
||||||
|
free(string as *mut libc::c_void);
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
*(*string).str_0.offset(0isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_new_len(
|
||||||
|
mut init: *const libc::c_char,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
let mut string: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
if len <= 0i32 as libc::size_t {
|
||||||
|
return mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||||
|
} else {
|
||||||
|
string = mmap_string_sized_new(len);
|
||||||
|
if string.is_null() {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
if !init.is_null() {
|
||||||
|
mmap_string_append_len(string, init, len);
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_append_len(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_len(string, (*string).len, val, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_free(mut string: *mut MMAPString) {
|
||||||
|
if string.is_null() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free((*string).str_0 as *mut libc::c_void);
|
||||||
|
free(string as *mut libc::c_void);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_assign(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut rval: *const libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
mmap_string_truncate(string, 0i32 as size_t);
|
||||||
|
if mmap_string_append(string, rval).is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_truncate(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
(*string).len = if len < (*string).len {
|
||||||
|
len
|
||||||
|
} else {
|
||||||
|
(*string).len
|
||||||
|
};
|
||||||
|
*(*string).str_0.offset((*string).len as isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_set_size(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
if len >= (*string).allocated_len {
|
||||||
|
if mmap_string_maybe_expand(string, len.wrapping_sub((*string).len)).is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*string).len = len;
|
||||||
|
*(*string).str_0.offset(len as isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_append_c(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut c: libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_c(string, (*string).len, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_insert_c(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut pos: size_t,
|
||||||
|
mut c: libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
if mmap_string_maybe_expand(string, 1i32 as size_t).is_null() {
|
||||||
|
return 0 as *mut MMAPString;
|
||||||
|
}
|
||||||
|
if pos < (*string).len {
|
||||||
|
memmove(
|
||||||
|
(*string).str_0.offset(pos as isize).offset(1isize) as *mut libc::c_void,
|
||||||
|
(*string).str_0.offset(pos as isize) as *const libc::c_void,
|
||||||
|
(*string).len.wrapping_sub(pos),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*(*string).str_0.offset(pos as isize) = c;
|
||||||
|
(*string).len =
|
||||||
|
((*string).len as libc::size_t).wrapping_add(1i32 as libc::size_t) as size_t as size_t;
|
||||||
|
*(*string).str_0.offset((*string).len as isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_prepend(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_len(string, 0i32 as size_t, val, strlen(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_prepend_c(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut c: libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_c(string, 0i32 as size_t, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_prepend_len(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_len(string, 0i32 as size_t, val, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_insert(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut pos: size_t,
|
||||||
|
mut val: *const libc::c_char,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
return mmap_string_insert_len(string, pos, val, strlen(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_erase(
|
||||||
|
mut string: *mut MMAPString,
|
||||||
|
mut pos: size_t,
|
||||||
|
mut len: size_t,
|
||||||
|
) -> *mut MMAPString {
|
||||||
|
if pos.wrapping_add(len) < (*string).len {
|
||||||
|
memmove(
|
||||||
|
(*string).str_0.offset(pos as isize) as *mut libc::c_void,
|
||||||
|
(*string).str_0.offset(pos as isize).offset(len as isize) as *const libc::c_void,
|
||||||
|
(*string).len.wrapping_sub(pos.wrapping_add(len)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(*string).len = ((*string).len as libc::size_t).wrapping_sub(len) as size_t as size_t;
|
||||||
|
*(*string).str_0.offset((*string).len as isize) = 0i32 as libc::c_char;
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_set_ceil(mut ceil: size_t) {
|
||||||
|
mmap_string_ceil = ceil;
|
||||||
|
}
|
||||||
|
static mut mmap_string_ceil: size_t = (8i32 * 1024i32 * 1024i32) as size_t;
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_ref(mut string: *mut MMAPString) -> libc::c_int {
|
||||||
|
let mut ht: *mut chash = 0 as *mut chash;
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
let mut key: chashdatum = chashdatum {
|
||||||
|
data: 0 as *mut libc::c_void,
|
||||||
|
len: 0,
|
||||||
|
};
|
||||||
|
let mut data: chashdatum = chashdatum {
|
||||||
|
data: 0 as *mut libc::c_void,
|
||||||
|
len: 0,
|
||||||
|
};
|
||||||
|
mmapstring_lock.lock().unwrap();
|
||||||
|
if mmapstring_hashtable.is_null() {
|
||||||
|
mmapstring_hashtable_init();
|
||||||
|
}
|
||||||
|
ht = mmapstring_hashtable;
|
||||||
|
if ht.is_null() {
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
key.data = &mut (*string).str_0 as *mut *mut libc::c_char as *mut libc::c_void;
|
||||||
|
key.len = ::std::mem::size_of::<*mut libc::c_char>() as libc::size_t as libc::c_uint;
|
||||||
|
data.data = string as *mut libc::c_void;
|
||||||
|
data.len = 0i32 as libc::c_uint;
|
||||||
|
r = chash_set(
|
||||||
|
mmapstring_hashtable,
|
||||||
|
&mut key,
|
||||||
|
&mut data,
|
||||||
|
0 as *mut chashdatum,
|
||||||
|
);
|
||||||
|
|
||||||
|
if r < 0i32 {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
return 0i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
static mut mmapstring_hashtable: *mut chash = 0 as *const chash as *mut chash;
|
||||||
|
unsafe fn mmapstring_hashtable_init() {
|
||||||
|
mmapstring_hashtable = chash_new(13i32 as libc::c_uint, 1i32);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmap_string_unref(mut str: *mut libc::c_char) -> libc::c_int {
|
||||||
|
let mut string: *mut MMAPString = 0 as *mut MMAPString;
|
||||||
|
let mut ht: *mut chash = 0 as *mut chash;
|
||||||
|
let mut key: chashdatum = chashdatum {
|
||||||
|
data: 0 as *mut libc::c_void,
|
||||||
|
len: 0,
|
||||||
|
};
|
||||||
|
let mut data: chashdatum = chashdatum {
|
||||||
|
data: 0 as *mut libc::c_void,
|
||||||
|
len: 0,
|
||||||
|
};
|
||||||
|
let mut r: libc::c_int = 0;
|
||||||
|
if str.is_null() {
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
mmapstring_lock.lock().unwrap();
|
||||||
|
ht = mmapstring_hashtable;
|
||||||
|
if ht.is_null() {
|
||||||
|
return -1i32;
|
||||||
|
}
|
||||||
|
key.data = &mut str as *mut *mut libc::c_char as *mut libc::c_void;
|
||||||
|
key.len = ::std::mem::size_of::<*mut libc::c_char>() as libc::size_t as libc::c_uint;
|
||||||
|
r = chash_get(ht, &mut key, &mut data);
|
||||||
|
if r < 0i32 {
|
||||||
|
string = 0 as *mut MMAPString
|
||||||
|
} else {
|
||||||
|
string = data.data as *mut MMAPString
|
||||||
|
}
|
||||||
|
if !string.is_null() {
|
||||||
|
chash_delete(ht, &mut key, 0 as *mut chashdatum);
|
||||||
|
if chash_count(ht) == 0i32 as libc::c_uint {
|
||||||
|
chash_free(ht);
|
||||||
|
mmapstring_hashtable = 0 as *mut chash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !string.is_null() {
|
||||||
|
mmap_string_free(string);
|
||||||
|
return 0i32;
|
||||||
|
} else {
|
||||||
|
return -1i32;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
unsafe fn chash_count(mut hash: *mut chash) -> libc::c_uint {
|
||||||
|
return (*hash).count;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mmapstring_init_lock() {}
|
||||||
|
pub unsafe fn mmapstring_uninit_lock() {}
|
||||||
1707
mmime/src/other.rs
Normal file
1707
mmime/src/other.rs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user