-
Notifications
You must be signed in to change notification settings - Fork 1
/
MailSender.sol
77 lines (65 loc) · 2.36 KB
/
MailSender.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import "./EthereumPostalService.sol";
abstract contract MailSender {
EthereumPostalService public eps;
constructor(address _ethereumPostalService) {
eps = EthereumPostalService(_ethereumPostalService);
}
modifier sendsMail() {
(
string memory addressLine1,
string memory addressLine2,
string memory city,
string memory countryCode,
string memory postalOrZip,
string memory name,
string memory htmlMessage
) = mailFields();
EthereumPostalService.PostalAddress memory postalAddress =
EthereumPostalService.PostalAddress(addressLine1, addressLine2, city, countryCode, postalOrZip, name);
uint256 postageCost = eps.getPostageWei();
eps.sendMail{value: postageCost}(postalAddress, htmlMessage);
if (msg.value > postageCost) {
bool refunded = payable(address(msg.sender)).send(msg.value - postageCost);
if (!refunded) {
revert RefundFailed(msg.sender);
}
}
_;
}
modifier sendsEncryptedMail() {
(
string memory addressLine1,
string memory addressLine2,
string memory city,
string memory countryCode,
string memory postalOrZip,
string memory name,
string memory htmlMessage
) = mailFields();
EthereumPostalService.PostalAddress memory postalAddress =
EthereumPostalService.PostalAddress(addressLine1, addressLine2, city, countryCode, postalOrZip, name);
uint256 postageCost = eps.getPostageWei();
eps.sendEncryptedMail{value: postageCost}(postalAddress, htmlMessage, true, true);
if (msg.value > postageCost) {
bool refunded = payable(address(msg.sender)).send(msg.value - postageCost);
if (!refunded) {
revert RefundFailed(msg.sender);
}
}
_;
}
function mailFields()
public
virtual
returns (
string memory addressLine1,
string memory addressLine2,
string memory city,
string memory countryCode,
string memory postalOrZip,
string memory name,
string memory htmlMessage
);
}