im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! `/admin/message`: a message from the administrator to every enabled account. |
| 2 | //! |
| 3 | //! The message is queued as one mail per account, in that account's language, through the same outbox as |
| 4 | //! every other mail. The subject is one line of at most 150 characters; the body is at most 10 000 |
| 5 | //! characters, and blank lines separate its paragraphs. Each send counts against a small rate limit, so a |
| 6 | //! form that is submitted again and again cannot queue thousands of mails. |
| 7 | |
| 8 | use Instant; |
| 9 | |
| 10 | use AuditAction; |
| 11 | use ; |
| 12 | use Deserialize; |
| 13 | use json; |
| 14 | use Result; |
| 15 | use ; |
| 16 | use Form; |
| 17 | use SeeOther; |
| 18 | use ; |
| 19 | use ; |
| 20 | |
| 21 | use crate; |
| 22 | use crate; |
| 23 | use crateLang; |
| 24 | use crate; |
| 25 | use crate; |
| 26 | use crate |
| 27 | |
| 28 | |
| 29 | ; |
| 30 | use crateAppState; |
| 31 | use crate; |
| 32 | |
| 33 | /// The longest subject, in characters. |
| 34 | const SUBJECT_MAX: usize = 150; |
| 35 | |
| 36 | /// The longest body, in characters. |
| 37 | const BODY_MAX: usize = 10_000; |
| 38 | |
| 39 | /// Sends that the limit allows in one window of the throttle. |
| 40 | const SENDS_PER_WINDOW: usize = 5; |
| 41 | |
| 42 | /// Path of the message form. The router raises the body limit for this path (see `boot.rs`). |
| 43 | pub const MESSAGE_ROUTE: &str = "/admin/message"; |
| 44 | |
| 45 | /// The body limit of the message form: every character of the subject and the body at its longest |
| 46 | /// encoding (4 bytes of UTF-8, 3 bytes each once percent-encoded), plus room for the field names and the |
| 47 | /// CSRF token. Smaller would refuse a long Turkish or CJK message before its own length check runs. |
| 48 | pub const MESSAGE_BODY_LIMIT: usize = * 4 * 3 + 4 * 1024; |
| 49 | |
| 50 | /// The throttle key of the message form. |
| 51 | const THROTTLE_KEY: &str = "admin-message"; |
| 52 | |
| 53 | /// The message form. |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | /// `GET /admin/message`. |
| 65 | |
| 66 | async |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | /// `POST /admin/message`: queues the message for every enabled account. |
| 80 | |
| 81 | async |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | /// The message page: the subject and body fields, and the send button. |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 |