Question téléchargement Pièce jointe
- chevalier
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 5
- Remerciements reçus 0
je souhaite récupérer la pièce jointe d'un e-mail.
Cela fonctionne, bcp de personne explique comment faire mais j'ai tout de même un soucis, en effet quand la personne qui envoi le mail possède un signature avec image, le script récupéré les image de la signature...
Est il possible de distinguer cela?
$email = \"******\"
$username = \"*****\"
$password = \"*****\"
$domain = \"*******\"
$smtpServer = \"****8\"
$enc = New-Object System.Text.utf8encoding
#
connection a la BAL
[Reflection.Assembly]::LoadFile(\"C:\Interfaces\scripts\Robot\Microsoft.Exchange.WebServices.dll\")
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain)
$s.AutodiscoverUrl($email)
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
#create a property set (to let us access the body & other details not available from the FindItems call)
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(9999)
$searchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
$items = $inbox.FindItems($searchFilter, $view)
foreach ($item in $items.Items)
{
$item.load($psPropertySet)
$pj= $item.attachments
#echo $pj
#if ($pj.ContentId -eq $null #
# {
#echo \"ta mere\"
# }
$downloadDirectory = \"c:\sofinord\"
$item.Load()
foreach($attach in $item.Attachments){
$attach.Load()
if ($pj.ContentId -ne $null)
{
$fiFile = new-object System.IO.FileStream(($downloadDirectory + “\” + (Get-Date -Format \"ddMMyyyy\") + \"_\" + $attach.Name.ToString()), [System.IO.FileMode]::Create)
$fiFile.Write($attach.Content, 0, $attach.Content.Length)
$fiFile.Close()
echo $pj.ContentId
#write-host \"Downloaded Attachment : \" + (($downloadDirectory + “\” + (Get-Date -Format \"ddMMyyyy\") + \"_\" + $attach.Name.ToString()))
}
}
}
Une idée?
Merci et bonne journée
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
- Messages : 6311
- Remerciements reçus 68
déterminer si le fichier est une image ?:
[code:1]
Function IsIconImage{
#valide si un fichier est du type attendu, ici un fichier Icon ( .ico )
param($Filename)
try
{
$Img = [System.Drawing.Image]::FromFile($Filename)
return $img.RawFormat.Equals([System.Drawing.Imaging.ImageFormat]::Icon)
}
catch [System.IO.FileNotFoundException], [System.OutOfMemoryException]
{
return $false;
}
finally {
if ($Img -ne $Null)
{$Img.Dispose()}
}
}#isIconImage
[/code:1]
Les formats reconnus :
[code:1][System.Drawing.Imaging.ImageFormat].GetMembers()|% {$_.name}[/code:1]
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Richard Lazaro
- Hors Ligne
- Membre platinium
-
- Messages : 530
- Remerciements reçus 0
Petit soucis, c'est que tu peux avoir desi mages en pièce jointe
En idée j'aurais :
Analyse du corps du mail (car surement en HTML) et essayer de détecter une signatures avec des images.
Si oui, retirer les images de la listes des pièces jointes qui sont récupérées.
Compliqué quand même ...
Think-MS : (Get-Life).Days | %{ Learn-More }
\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein
Connexion ou Créer un compte pour participer à la conversation.
- chevalier
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 5
- Remerciements reçus 0
Salut,
déterminer si le fichier est une image ?:
[code:1]
Function IsIconImage{
#valide si un fichier est du type attendu, ici un fichier Icon ( .ico )
param($Filename)
try
{
$Img = [System.Drawing.Image]::FromFile($Filename)
return $img.RawFormat.Equals([System.Drawing.Imaging.ImageFormat]::Icon)
}
catch [System.IO.FileNotFoundException], [System.OutOfMemoryException]
{
return $false;
}
finally {
if ($Img -ne $Null)
{$Img.Dispose()}
}
}#isIconImage
[/code:1]
Les formats reconnus :
[code:1][System.Drawing.Imaging.ImageFormat].GetMembers()|% {$_.name}[/code:1]
oui image dans la signature
Connexion ou Créer un compte pour participer à la conversation.
- chevalier
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
- Messages : 5
- Remerciements reçus 0
@Laurent:
Petit soucis, c'est que tu peux avoir desi mages en pièce jointe
En idée j'aurais :
Analyse du corps du mail (car surement en HTML) et essayer de détecter une signatures avec des images.
Si oui, retirer les images de la listes des pièces jointes qui sont récupérées.
Compliqué quand même ...
en effet compliqué
impossible de lire en mail en text brut et non html?
Connexion ou Créer un compte pour participer à la conversation.
- Richard Lazaro
- Hors Ligne
- Membre platinium
-
- Messages : 530
- Remerciements reçus 0
Think-MS : (Get-Life).Days | %{ Learn-More }
\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein
Connexion ou Créer un compte pour participer à la conversation.
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les initiés
- téléchargement Pièce jointe