| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::Imap::Client - IMAP Client | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASSES | ||||||||||
| 10 | |||||||||||
| 11 | =over 2 | ||||||||||
| 12 | |||||||||||
| 13 | =item * | ||||||||||
| 14 | |||||||||||
| 15 | Net::IMAP::Simple | ||||||||||
| 16 | |||||||||||
| 17 | =item * | ||||||||||
| 18 | |||||||||||
| 19 | L<Quiq::Object> | ||||||||||
| 20 | |||||||||||
| 21 | =back | ||||||||||
| 22 | |||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||
| 24 | |||||||||||
| 25 | Ein Objekt der Klasse repräsentiert einen IMAP-Client. | ||||||||||
| 26 | |||||||||||
| 27 | Die Klasse realisiert ihre Funktionalität unter Rückgriff auf | ||||||||||
| 28 | L<Net::IMAP::Simple|https://metacpan.org/pod/Net::IMAP::Simple> durch Ableitung. | ||||||||||
| 29 | Detaillierte Dokumentation siehe dort. | ||||||||||
| 30 | |||||||||||
| 31 | Die Klasse zeichnet sich gegenüber ihrer Basisklasse dadurch aus, dass | ||||||||||
| 32 | |||||||||||
| 33 | =over 2 | ||||||||||
| 34 | |||||||||||
| 35 | =item * | ||||||||||
| 36 | |||||||||||
| 37 | sie Fehler nicht über Returnwerte anzeigt, sondern im Fehlerfall | ||||||||||
| 38 | eine Exception wirft | ||||||||||
| 39 | |||||||||||
| 40 | =item * | ||||||||||
| 41 | |||||||||||
| 42 | die Methode get() die Mail als vollständigen Text liefert | ||||||||||
| 43 | |||||||||||
| 44 | =back | ||||||||||
| 45 | |||||||||||
| 46 | Der Mail-Text kann zur Instantiierung eines Objekts zur weiteren | ||||||||||
| 47 | Verarbeitung genutzt werden kann (z.B. via Email::Simple, Email::MIME | ||||||||||
| 48 | oder MIME::Parser) | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | # ----------------------------------------------------------------------------- | ||||||||||
| 53 | |||||||||||
| 54 | package Quiq::Imap::Client; | ||||||||||
| 55 | 1 | ▶ | use base qw/Net::IMAP::Simple Quiq::Object/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | 1 | our $VERSION = '1.240'; | |||||||||
| 62 | |||||||||||
| 63 | # ----------------------------------------------------------------------------- | ||||||||||
| 64 | |||||||||||
| 65 | =head1 METHODS | ||||||||||
| 66 | |||||||||||
| 67 | =head2 Konstruktor | ||||||||||
| 68 | |||||||||||
| 69 | =head3 new() - Instantiiere Objekt | ||||||||||
| 70 | |||||||||||
| 71 | =head4 Synopsis | ||||||||||
| 72 | |||||||||||
| 73 | $imap = $class->new($host,%opt); | ||||||||||
| 74 | |||||||||||
| 75 | =head4 Arguments | ||||||||||
| 76 | |||||||||||
| 77 | =over 4 | ||||||||||
| 78 | |||||||||||
| 79 | =item $host | ||||||||||
| 80 | |||||||||||
| 81 | (String) IMAP-Host, ggf. mit Port | ||||||||||
| 82 | |||||||||||
| 83 | =item %opt | ||||||||||
| 84 | |||||||||||
| 85 | Optionale Angaben als Schlüssel/Wert-Paare | ||||||||||
| 86 | |||||||||||
| 87 | =back | ||||||||||
| 88 | |||||||||||
| 89 | =head4 Returns | ||||||||||
| 90 | |||||||||||
| 91 | Object | ||||||||||
| 92 | |||||||||||
| 93 | =head4 Description | ||||||||||
| 94 | |||||||||||
| 95 | Instantiiere eine Objekt der Klasse und liefere eine Referenz auf | ||||||||||
| 96 | dieses Objekt zurück. | ||||||||||
| 97 | |||||||||||
| 98 | =head4 Example | ||||||||||
| 99 | |||||||||||
| 100 | my $imap = Quiq::Imap::Client->new('imap.example.com'); | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | # ----------------------------------------------------------------------------- | ||||||||||
| 105 | |||||||||||
| 106 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 107 | 0 | my ($class,$host) = splice @_,0,2; | |||||||||
| 108 | # @_: %opt | ||||||||||
| 109 | |||||||||||
| 110 | 0 | my $self = $class->SUPER::new($host,@_); | |||||||||
| 111 | 0 | ▶ | if (!$self) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | 0 | $class->throw( | |||||||||
| 113 | 'IMAP-00099: Object instatiation failed', | ||||||||||
| 114 | Message => $Net::IMAP::Simple::errstr, | ||||||||||
| 115 | ); | ||||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 0 | return $self; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | # ----------------------------------------------------------------------------- | ||||||||||
| 122 | |||||||||||
| 123 | =head2 Objektmethoden | ||||||||||
| 124 | |||||||||||
| 125 | =head3 login() - Führe Authentisierung gegenüber Server durch | ||||||||||
| 126 | |||||||||||
| 127 | =head4 Synopsis | ||||||||||
| 128 | |||||||||||
| 129 | $imap->login($user,$password); | ||||||||||
| 130 | |||||||||||
| 131 | =head4 Arguments | ||||||||||
| 132 | |||||||||||
| 133 | =over 4 | ||||||||||
| 134 | |||||||||||
| 135 | =item $user | ||||||||||
| 136 | |||||||||||
| 137 | (String) Name des Benutzers | ||||||||||
| 138 | |||||||||||
| 139 | =item $password | ||||||||||
| 140 | |||||||||||
| 141 | (String) Passwort des Benutzers | ||||||||||
| 142 | |||||||||||
| 143 | =back | ||||||||||
| 144 | |||||||||||
| 145 | =head4 Description | ||||||||||
| 146 | |||||||||||
| 147 | Führe eine Authetisierung gegenüber dem Server durch. | ||||||||||
| 148 | |||||||||||
| 149 | =head4 Example | ||||||||||
| 150 | |||||||||||
| 151 | $imap->login('kallisto','geheim'); | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | # ----------------------------------------------------------------------------- | ||||||||||
| 156 | |||||||||||
| 157 | 0 | ▶ | sub login { | ||||||||
|
Subroutine
login: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 158 | 0 | my ($self,$user,$password) = @_; | |||||||||
| 159 | |||||||||||
| 160 | 0 | my $bool = $self->SUPER::login($user,$password); | |||||||||
| 161 | 0 | ▶ | if (!$bool) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | 0 | $self->throw( | |||||||||
| 163 | 'IMAP-00099: Authentication failed', | ||||||||||
| 164 | User => $user, | ||||||||||
| 165 | Message => $self->errstr, | ||||||||||
| 166 | ); | ||||||||||
| 167 | } | ||||||||||
| 168 | |||||||||||
| 169 | 0 | return; | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | # ----------------------------------------------------------------------------- | ||||||||||
| 173 | |||||||||||
| 174 | =head3 select() - Wähle Verzeichnis | ||||||||||
| 175 | |||||||||||
| 176 | =head4 Synopsis | ||||||||||
| 177 | |||||||||||
| 178 | $n = $imap->select($folder); | ||||||||||
| 179 | |||||||||||
| 180 | =head4 Arguments | ||||||||||
| 181 | |||||||||||
| 182 | =over 4 | ||||||||||
| 183 | |||||||||||
| 184 | =item $folder | ||||||||||
| 185 | |||||||||||
| 186 | (String) Name des Verzeichnisses | ||||||||||
| 187 | |||||||||||
| 188 | =back | ||||||||||
| 189 | |||||||||||
| 190 | =head4 Returns | ||||||||||
| 191 | |||||||||||
| 192 | (Integer) Anzahl der Mails im Verzeichnis | ||||||||||
| 193 | |||||||||||
| 194 | =head4 Description | ||||||||||
| 195 | |||||||||||
| 196 | Wähle Verzeichnis $folder aus und liefere die Anzahl der darin enthaltenen | ||||||||||
| 197 | Mails zurück. | ||||||||||
| 198 | |||||||||||
| 199 | =head4 Example | ||||||||||
| 200 | |||||||||||
| 201 | $n = $imap->select('INBOX'); | ||||||||||
| 202 | |||||||||||
| 203 | =cut | ||||||||||
| 204 | |||||||||||
| 205 | # ----------------------------------------------------------------------------- | ||||||||||
| 206 | |||||||||||
| 207 | 0 | ▶ | sub select { | ||||||||
|
Subroutine
select: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 208 | 0 | my ($self,$folder) = @_; | |||||||||
| 209 | |||||||||||
| 210 | 0 | my $n = $self->SUPER::select($folder); | |||||||||
| 211 | 0 | ▶ | if (!defined $n) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 212 | 0 | $self->throw( | |||||||||
| 213 | 'IMAP-00099: Selection of folder failed', | ||||||||||
| 214 | Folder => $folder, | ||||||||||
| 215 | Message => $self->errstr, | ||||||||||
| 216 | ); | ||||||||||
| 217 | } | ||||||||||
| 218 | |||||||||||
| 219 | 0 | return $n; | |||||||||
| 220 | } | ||||||||||
| 221 | |||||||||||
| 222 | # ----------------------------------------------------------------------------- | ||||||||||
| 223 | |||||||||||
| 224 | =head3 search() - Suche Mails | ||||||||||
| 225 | |||||||||||
| 226 | =head4 Synopsis | ||||||||||
| 227 | |||||||||||
| 228 | @arr = $imap->search($query); | ||||||||||
| 229 | |||||||||||
| 230 | =head4 Arguments | ||||||||||
| 231 | |||||||||||
| 232 | =over 4 | ||||||||||
| 233 | |||||||||||
| 234 | =item $query | ||||||||||
| 235 | |||||||||||
| 236 | (String) Anfrage-Zeichenkette (Details s. Originaldoku) | ||||||||||
| 237 | |||||||||||
| 238 | =back | ||||||||||
| 239 | |||||||||||
| 240 | =head4 Returns | ||||||||||
| 241 | |||||||||||
| 242 | (Array) Liste der Mail-Nummern | ||||||||||
| 243 | |||||||||||
| 244 | =head4 Description | ||||||||||
| 245 | |||||||||||
| 246 | Suche alle Mails im ausgewählten Verzeichnis (s. $imap->select()) | ||||||||||
| 247 | und liefere die Liste der Mail-Nummern zurück. | ||||||||||
| 248 | |||||||||||
| 249 | =head4 Example | ||||||||||
| 250 | |||||||||||
| 251 | @arr = $imap->search('FROM "john@example.com"'); | ||||||||||
| 252 | |||||||||||
| 253 | =cut | ||||||||||
| 254 | |||||||||||
| 255 | # ----------------------------------------------------------------------------- | ||||||||||
| 256 | |||||||||||
| 257 | # Implementierung in der Basisklasse | ||||||||||
| 258 | |||||||||||
| 259 | # ----------------------------------------------------------------------------- | ||||||||||
| 260 | |||||||||||
| 261 | =head3 get() - Liefere Mail als Text | ||||||||||
| 262 | |||||||||||
| 263 | =head4 Synopsis | ||||||||||
| 264 | |||||||||||
| 265 | $message = $imap->get($i); | ||||||||||
| 266 | |||||||||||
| 267 | =head4 Arguments | ||||||||||
| 268 | |||||||||||
| 269 | =over 4 | ||||||||||
| 270 | |||||||||||
| 271 | =item $i | ||||||||||
| 272 | |||||||||||
| 273 | (Integer) Mail-Nummer innerhalb des Verzeichnisses | ||||||||||
| 274 | |||||||||||
| 275 | =back | ||||||||||
| 276 | |||||||||||
| 277 | =head4 Returns | ||||||||||
| 278 | |||||||||||
| 279 | (String) Mail als Zeichenkette | ||||||||||
| 280 | |||||||||||
| 281 | =head4 Description | ||||||||||
| 282 | |||||||||||
| 283 | Hole die Mail mit der Nummer $i aus dem gewählten IMAP-Verzeichnis | ||||||||||
| 284 | und liefere sie als Zeichnkette zurück. | ||||||||||
| 285 | |||||||||||
| 286 | =cut | ||||||||||
| 287 | |||||||||||
| 288 | # ----------------------------------------------------------------------------- | ||||||||||
| 289 | |||||||||||
| 290 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 291 | 0 | my ($self,$i) = @_; | |||||||||
| 292 | |||||||||||
| 293 | 0 | my $message = $self->SUPER::get($i); | |||||||||
| 294 | 0 | ▶ | if (!defined $message) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 295 | 0 | $self->throw( | |||||||||
| 296 | 'IMAP-00099: Can\'t fetch message', | ||||||||||
| 297 | Numer => $i, | ||||||||||
| 298 | Message => $self->errstr, | ||||||||||
| 299 | ); | ||||||||||
| 300 | } | ||||||||||
| 301 | |||||||||||
| 302 | 0 | return "$message"; | |||||||||
| 303 | } | ||||||||||
| 304 | |||||||||||
| 305 | # ----------------------------------------------------------------------------- | ||||||||||
| 306 | |||||||||||
| 307 | =head1 VERSION | ||||||||||
| 308 | |||||||||||
| 309 | 1.240 | ||||||||||
| 310 | |||||||||||
| 311 | =head1 AUTHOR | ||||||||||
| 312 | |||||||||||
| 313 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 314 | |||||||||||
| 315 | =head1 COPYRIGHT | ||||||||||
| 316 | |||||||||||
| 317 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 318 | |||||||||||
| 319 | =head1 LICENSE | ||||||||||
| 320 | |||||||||||
| 321 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 322 | it under the same terms as Perl itself. | ||||||||||
| 323 | |||||||||||
| 324 | =cut | ||||||||||
| 325 | |||||||||||
| 326 | # ----------------------------------------------------------------------------- | ||||||||||
| 327 | |||||||||||
| 328 | 1 | 1; | |||||||||
| 329 | |||||||||||
| 330 | # eof | ||||||||||